Saving image to a folder [Solved/Closed]

mikeoe2003 25 Posts Thursday November 1, 2012Registration date March 27, 2014 Last seen - Apr 2, 2013 at 02:23 PM - Latest reply: Zohaib R 2421 Posts Sunday September 23, 2012Registration date July 16, 2018 Last seen
- 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
See more 

3 replies

Zohaib R 2421 Posts Sunday September 23, 2012Registration date July 16, 2018 Last seen - Apr 3, 2013 at 03:44 AM
0
Thank you
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
Thank you
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
Zohaib R 2421 Posts Sunday September 23, 2012Registration date July 16, 2018 Last seen - Apr 6, 2013 at 12:56 AM
0
Thank you
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.