Picture Box Problem

stanbuggy

Member
Joined
Oct 25, 2010
Messages
18
Programming Experience
Beginner
Hi Guys, i have this problem i would want to solve urgently...when i import a picture into my picture box in vb.net using this code

Dim img As Image

OpenFileDialog1.Filter = "images|*.gif;*png;*jpg;*.ico"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
img = Image.FromFile(OpenFileDialog1.FileName)
PictureBox1.Image = img.GetThumbnailImage(144, 142, Nothing, Nothing)

End If
i want a suitation when i click my submit button the image uploaded into the picture box is copied to a folder so i dont have to deal with a complete path problem whenever i move my application to another system.

I hope u get my problem..

here is my code for submitting into the database

query5 = "insert into students(regnum,name,tel,addy,email,sex,date_reg,pix,course,duration,amount,class_ses) values ('" & txtregnum.Text & "','" & txtfname.Text & "','" & txttel.Text & "','" & txtaddy.Text & "','" & txtemail.Text & "','" & cmbsex.Text & "','" & dtpreg.Text & "','" & OpenFileDialog1.FileName & "','" & cmbcourse.Text & "','" & txtduration.Text & "','" & txtprice.Text & "','" & session.Text & "')"
dataconn5 = New SqlCommand(query5, conn5)
dataconn5.ExecuteNonQuery()

img = Image.FromFile("C:\Documents and Settings\stanley\My Documents\My Pictures\img_large_watermarked.jpg")
PictureBox1.Image = img.GetThumbnailImage(174, 188, Nothing, Nothing)

The img_large_watermarked.jpg image shows up on successful submission...i also want to change that too..cos as soon as i moved systems it could not detect C:\Documents and Settings\stanley\My Documents\My Pictures\img_large_watermarked.jpg and that caused errors.

So pls buddies i need help.

Thanks in Advance and have a Blessed 2011
 
A good option would be to copy your images into a specific subfolder under the application data folder. That folder may be in different locations on different systems but the Framework will always find it for you:
VB.NET:
IO.File.Copy(OpenFileDialog1.FileName, _
             IO.Path.Combine(Application.CommonAppDataPath, _
                             IO.Path.GetFileName(OpenFileDialog1.FileName)))
 
Thanks mate..but where would i put this line of code u just gave me...and how do i specify the folder...will i do this during submission or where?

Appreciate ur help mate.
 
You tell me where. What does that code do? It copies the file selected by the user from its original location to the common app data folder. Where do you want to do that? That's where you put the code.
 
Would try it and when i stumble into any problem ..pls dont be tired to help me out! Thanks a Million Mate
 
Back
Top