Click here to Skip to main content
11,931,584 members (67,126 online)
Rate this:
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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.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