# [.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.

## 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 on other sites
string FileName = OpenFileDialog.FileName.Substring ( OpenFIleDialog.FileName.LastIndexOf ( "/" ) + 1 );

or something like that.

##### Share on other sites
Thank you very much. I also found another method:

System.IO.Path.GetFileNameWithoutExtension(FileName)

##### Share on other sites
Quote:
 Original post by hungryhippo5000Thank 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.