How do I display the filename only with openfiledialog

shurb

Member
Joined
Oct 9, 2007
Messages
16
Programming Experience
1-3
I am trying to find out how to display only the filename of the file I wish to open without the full directory path. For example I want to open file test.txt which is located in c:\program files\windows.

In txtFilePath.text I want to display the file name only, (test.txt). Instead I can only get it to display c:\program files\windows\test.txt

Is there anything I can add to the following piece below to do so?

openFileDialog2.InitialDirectory = txtFilePath.Text
openFileDialog2.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog2.FilterIndex = 1
openFileDialog2.RestoreDirectory = False
 
Back
Top