Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This:
Dim filename As String = System.IO.Path.GetFileName(saveFileDialog1.FileName)

Will result in a string that will display in MsgBox but will crash the program if this is used as the string name for saving. I've checked once it crashed and it's identical to a working string.
Posted

1 solution

Yeah....that's....ummm....badly written code. it makes a rather HUGE assumption. That would be that the user actually selected a filename and not hit Cancel instead.

Don't combine the two operations here. Just ShowDialog the SFD and CHECK THE RESULT TO SEE IF IT IS VALID before passing it to Path.GetFilename.
 
Share this answer
 
Comments
kamikazehighland 18-Jan-13 20:42pm    
And then what?
Dave Kreskowiak 18-Jan-13 20:57pm    
WTF do you mean "then what"?? YOU'VE GOT YOUR FILENAME! Do whatever you were going to do with it.
Dave Kreskowiak 19-Jan-13 0:38am    
And what's the EXACT exception message you're getting??
kamikazehighland 20-Jan-13 7:35am    
Thanks for your help! I was using the save dialog example from msdn, which includes a save file stream I had no use for. But it blocked me from saving to the file I chose in the save file dialog, and removing that part made it run fine.

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