Click here to Skip to main content
15,038,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.. i create a tool that need to save image.. there is no problem when saving the image but it's problem when i click the cancel button at window dialog to select the directory. there will be error warning appear.. can anyone help me to resolved the problem? tq. this is the code to save the file:

                Dim NewFileName As String = SaveImage.FileName
                My.Computer.FileSystem.WriteAllBytes(NewFileName, PicAndText, True)

1 solution

Microsoft's solution is the following piece of code after your ShowDialog():

If SaveImage.FileName <> "" Then

That checks to be sure their is a file name selected. Here is a link to the article:[^]
dinmail 2-Jun-12 10:07am
thanks sir..but i mean when click the save button the save image windows that is to select the directory for new image will appear and and i click the cancel button. it just problem with cancel button. its ok when i save it.
Tim Corey 2-Jun-12 19:21pm
I understand the problem is when you hit cancel. That is what the line of code above prevents. You check to see if a file name was selected. If that field is empty, you don't attempt to save the file and you are good (no error). Your error is occurring because your user is hitting cancel and then you are trying to read the file name they never selected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900