Search This Blog

Friday, January 24, 2014

Get file name C# Example

C# > Files > GetFileName

Returns the file name and extension of the specified path string.

Example:


Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document";
dlg.DefaultExt = ".doc";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
     string filename = dlg.FileName;
     filename  = System.IO.Path.GetFileName(filename);
}