Reputation: 31
How to display filename instead of full path when selecting file through OpenFileDialog in C# on visual studio 2010?
I tried of FileName, but it returns full path of file.
Upvotes: 0
Views: 2422
Reputation: 73502
Use Path.GetFileName method.
string fileName = Path.GetFileName(fileDialog.FileName);
If you want to exclude the extension you can use Path.GetFileNameWithoutExtension
Upvotes: 3
Reputation: 222722
OpenFileDialog.SafeFileName
Gets the file name and extension for the file selected in the dialog box. The file name does not include the path.
Upvotes: 2