Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET
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 18-Jan-13 14:33pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
kamikazehighland at 18-Jan-13 20:42pm
   
And then what?
Dave Kreskowiak at 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 at 19-Jan-13 0:38am
   
And what's the EXACT exception message you're getting??
kamikazehighland at 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)

  Print Answers RSS
0 OriginalGriff 6,696
1 Sergey Alexandrovich Kryukov 6,675
2 CPallini 5,315
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 19 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100