Once you have the full path you coul just use the Path class to break it down.
Visual Basic:
Dim FullPath As String
Dim FileNameOnly As String
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
FullPath = OpenFileDialog1.FileName
FileNameOnly = System.IO.Path.GetFileName(FullPath)
End If
oh... since this topic is about the opendialog, i guess i could insert my question here as well. how come when the opendialogbox opens and i click the cancel button, the even causes an error. and for example i clicked the file that i want to open in the dialog box, but decided to not open it anymore (click the cancel button), the file is still open (assuming that my application opens files and views it in the application).
OpenFileDialog.Title = ("Open File")
OpenFileDialog.Filter = ("Text File (*.txt)|*.txt")
If OpenFileDialog.ShowDialog() = DialogResult.OK Then
'Open file
End If
I don't know if this is a property of the OpenFileDialog in .Net, but in the ActiveX version there is an property that is something like ErrorOnCancel to give you an option to throw an error when the user hits cancel.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.