• Advertisement
Sign in to follow this  

[.net] vb.net file name

This topic is 4950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I get just the name of a file without the directory paths, when using open or save dialogs? I get the full path when I use the following command: FileName = OpenFileDialog.FileName

Share this post


Link to post
Share on other sites
Advertisement
string FileName = OpenFileDialog.FileName.Substring ( OpenFIleDialog.FileName.LastIndexOf ( "/" ) + 1 );

or something like that.

Share this post


Link to post
Share on other sites
Quote:
Original post by hungryhippo5000
Thank you very much. I also found another method:

System.IO.Path.GetFileNameWithoutExtension(FileName)


The method I generally use is...


using System.IO;

...

FileInfo file = new FileInfo( fullName );
string fileName = file.Name;


Biggest problem is that it instantiates a FileInfo object, and returns it with an extension the same as System.IO.Path.GetFilename( FileName ). If you're doing any other manipulations to the file you might be better off with the FileInfo object for statistics, etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement