Grimm Grimm - 3 months ago 20
Vb.net Question

Upload image using OpenFileDialog and move/cut the image from its original location to another location

Please help. How could i transfer the image to another location using vb.net?

i've tried this strategy but its not working.

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
fullPath = dlg.FileName 'c:\Sample\image1.jpg
ImageFileName = Path.GetFileName(dlg.FileName) 'image1.jpg filename holder
PathHolder = Path.Combine("d:\FinalLocation", ImageFileName)
With PictureBox2
.Image = Image.FromFile(fullPath )
.SizeMode = PictureBoxSizeMode.Zoom
End With
End If
End Sub


THEN When user click save button i have a code like this

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
File.Move(fullPath, PathHolder) 'the 1st try
'System.IO.File.Move(fullPath, PathHolder) '2nd try but its not working at all
End Sub


Thanks in advance :)

Answer

thats is so easy. your code is correct but there is 1 line is missing in the save button.

try to add this..

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
picturebox2.image.dispose()
File.Move(fullPath, PathHolder)
End Sub

I think you cannot move the image to another location because it is still in use by the picturebox. just give it a try :)

Comments