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

1 solution

Rate this: bad
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.
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 605
1 Maciej Los 205
2 Abhinav S 171
3 Suvendu Shekhar Giri 159
4 Richard Deeming 150
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,095
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 19 Jan 2013
Copyright © CodeProject, 1999-2015
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