# [.net] vb.net file name

## 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
CWIZO    118
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
Talonius    643
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.