Saving and loading image files

I have a listbox(lstContacts) that displays my contacts. When I choose a contact from the list and then click "View" button , data related to him/her appears on left side of screen. On the left side of the screen, there's also an imagebox that displays his/her picture in an imagebox called picPhoto. Under that imagebox, button"Edit Picture" does the following.

 With dlgChoosePic
            .Filter = "Jpeg Files (*.jpg)|*.jpg|Gif Files (*.gif)|*.gif)|Bitmap Files (*.bmp)|*.bmp)"
            .Title = "Choose an image to use"
            If .ShowDialog <> DialogResult.OK Then Return

            If .FileName <> "" Then
                picPhoto.Image = Image.FromFile(.FileName)
            End If
        End With

As you'll see, i want user to be able to choose bmp's, jpeg's and gif's. But this does not save the image. How will i make it so that, when a contact's picture is selected after clicking "edit picture", program will pop up a message box asking "are you sure you want to use this picture as contact's display picture?" and when user clicks yes, it will automatically save the picture.
Later, when a contact is selected and "View" button is clicked, his/her picture in imagebox will appear automatically.
I'd really appreciate if you could give exact code for my need.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
>> When I choose a contact from the list and then click "View" button , data related to him/her appears on left side of screen.

You need to store the path to the image (dlgChoosePic.FileName) in the structure that holds the rest of the data for that contact.

Where and how is this data stored?

aeustaAuthor Commented:
Structure Contact

        Dim LName As String
        Dim FName As String
        Dim Category As String
        Dim Company As String
        Dim HPhone As String
        Dim WPhone As String
        Dim FPhone As String
        Dim MPhone As String
        Dim Email As String
        Dim MSN As String
        Dim AIM As String
        Dim Web As String
        Dim HAddress As String
        Dim HCity As String
        Dim HState As String
        Dim HZip As String
        Dim HCountry As String
        Dim WAddress As String
        Dim WCity As String
        Dim WState As String
        Dim WZip As String
        Dim WCountry As String

    End Structure  

This is the structure for contact. So far, i did nothing to save the image nor path to the image. I guess i need to say
Dim imagePath as String
into the structure?
I'm kinda confused, never dealt with images before.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right.  Adding imagePath to the structure would work just fine.

Then, when you load the data for that contact, you can check the imagePath value.  If it is not blank, then load the image in the same way as you did from the "Edit Picture" button, except that you use your stored image fileName instead of the one selected by the user from the dialog.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Mike TomlinsonMiddle School Assistant TeacherCommented:
>> I'm kinda confused, never dealt with images before.

With this approach you won't be saving the actual image in your structure, but only the full path and filename of the image.

I think you also want to save the image is it ??
May be when user selects the image and says OK yuo would like to save the image in a separate location and just store the name in the structure.

You can use picPhoto.Image.Save(Path) to save the image

aeustaAuthor Commented:
Idle Mind,
That's a smart way actually but i want the program to save the picture.

Arif Eqbal,
I tried : picPhoto.Image.Save("..\"), it gave following error.
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll

Additional information: A generic error occurred in GDI+.

Then i tried, picPhoto.Image.Save("..\pic") beucase tooltip says "inside paranthesis, i must write filename as String" , but this code does nothing, it does not work.
I would be surprised if it was this easy to save a file btw.
aeustaAuthor Commented:
I dont know if you guys use MSN messenger but what i exactly want is the "display picture" feature of msn messenger but without internet stuff.
When i click "edit picture" button, I should be able to browse folders, choose a picture, and the picture i chose must automatically appear in imagebox everytime i load contact's info.
I hope i'm clear enough.
aeustaAuthor Commented:
Idle Mind,
I gave up adding that function but gave you the points for your efforts.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.