Chandra Bhushan
Chandra Bhushan

Reputation: 31

show file name instead of full path in text box

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

Answers (2)

Sriram Sakthivel
Sriram Sakthivel

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

Sajeetharan
Sajeetharan

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

Related Questions