OpenFileDialog?

Getox

Centurion
Joined
Jul 8, 2004
Messages
122
Is there any way to just get the filename without the path? example:

you select file to open and click Open, it then puts the filename without the path like C:\blah\blah.ext it will put blah.ext

anyone know?
 
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
 
Ah thanks for that, Makin a webpage editing prog and when adding images it adds C:\blah\blah to it... But anymore, Thanks :D
 
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).
 
try this:

Visual Basic:
        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.
 
Back
Top