how do I get the short file name from the openfile dialog

I need to get just the filename of a file without the path after I open it  in vb.net
how do I do that?
Dov_BAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
You can use FileInfo() to get the filename only
 
Example:

        Dim fileDialog As New OpenFileDialog
        fileDialog.ShowDialog()
        Debug.WriteLine(New IO.FileInfo(fileDialog.FileName).Name)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rheitzmanCommented:
I assume you are not talking about the 8.3 name but just the filename:

x= My.Computer.FileSystem.GetName(OpenFileDialog1.FileName())

IO.FileInfo above works too but it is hard to use IMO, mainly because Intellisense doesn't work.

For some reason VB.Net has more than one way at the data - neither is very VB like.
0
mkosbieCommented:
Intellisense works fine with FileInfo, you just have to use it properly.  Either import the System.IO Namespace, or use System.IO.FileInfo to refer to the class.

As for having "multiple ways at the data" it's because the two classes are for very different tasks.  A FileInfo object represents an actual file on the file system and can be manipulated (renamed, deleted, read, etc).  My.Computer.FileSystem.GetName is JUST A PARSING function.  It reads the path and parses the name out of it.

If all you want is the name, definitely use My.Computer.FileSystem.GetName.  It has way less overhead and is designed for this task.
0
Jorge PaulinoIT Pro/DeveloperCommented:
If you use VS2008 you can also use:
 

        Dim fileDialog As New OpenFileDialog
        fileDialog.ShowDialog()
        Debug.WriteLine(fileDialog.SafeFileName)

Open in new window

0
Jorge PaulinoIT Pro/DeveloperCommented:
>> mainly because Intellisense doesn't work.
Intellisense works fine!
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.