Saving image to a folder

Solved/Closed
mikeoe2003 Posts 25 Registration date Thursday November 1, 2012 Status Member Last seen March 27, 2014 - Apr 2, 2013 at 02:23 PM
Zohaib R Posts 2368 Registration date Sunday September 23, 2012 Status Member Last seen December 13, 2018 - Apr 6, 2013 at 12:56 AM
i am trying to save image from picture box to particular folder and i get the

ERROR "the given path's format is not supported"

Please find below my code

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

OpenFileDialog1.Filter = "only images|*.jpg"
OpenFileDialog1.Title = "Select a file"
Dim s As String = Application.ExecutablePath & "\images\"
OpenFileDialog1.InitialDirectory = s
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.CheckFileExists = True Then
PictureBox1.ImageLocation = OpenFileDialog1.FileName.ToString
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Else
MsgBox("Please Select a Image")
End If
End Sub

Private Sub btnSavePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSavePic.Click
Try
Dim strBasepath As String
Dim strFilename As String
strFilename = OpenFileDialog1.FileName.ToString
strBasepath = Application.StartupPath & "\images"
If Directory.Exists(strBasepath) = False Then
Call Directory.CreateDirectory(strBasepath)
End If
'savefile()
Call PictureBox1.Image.Save(strBasepath & "\" & strFilename, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch fileException As Exception
Throw fileException
End Try

End Sub
Related:

3 responses

Zohaib R Posts 2368 Registration date Sunday September 23, 2012 Status Member Last seen December 13, 2018 69
Apr 3, 2013 at 03:44 AM
Hi mikeoe2003,

Good to see you in the forum after a long time. I found the fix for your problem.

Replace the following line:

strFilename = OpenFileDialog1.FileName.ToString

With:

strFilename = System.IO.Path.GetFileName(OpenFileDialog1.FileName.ToString())

And it should work.

Do reply with results.

Thanks & Regards
Zohaib R
#iworkfordell
0
thanks very much for your response i appreciate it very well. my project is on creating a database for a school record system and i look forward to assistance from you as always. thanks my dear friend
0
Zohaib R Posts 2368 Registration date Sunday September 23, 2012 Status Member Last seen December 13, 2018 69
Apr 6, 2013 at 12:56 AM
Hi mikeoe2003,

I am glad to know my tip was helpful for you. Surely, I will assist you further with your project. Let me know what help you need.

Please keep posting.
0