Link to home
Start Free TrialLog in
Avatar of webkiwi1
webkiwi1

asked on

OpenFileDialog - determine file type

Hello Experts,

VB.NET, Visual Studio 2005

I am using the code provided and would like to determine if the user picks an excel file.
What parameter do I check for .xls?

Thanks
OpenFileDialog1.Filter = "Text or Microsoft Excel Files (*.txt*; *.xls*)|*.txt; *.xls" ' Shows .txt and .xls files 
        OpenFileDialog1.FilterIndex = 1
        OpenFileDialog1.Title = "Browse to file:"

Open in new window

Avatar of VBRocks
VBRocks
Flag of United States of America image

       Dim ext As String = IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName)
        If ext = ".txt" OrElse ext = ".xls" Then

        End If

ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webkiwi1
webkiwi1

ASKER

VBRocks, that give me the file name without the extension...
sorry.  try the second post.

oops, our messages crossed.

Solution worked, THANKS!
Avatar of Mike Tomlinson
You could also create a FileInfo instance out of it like this:

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim fi As New System.IO.FileInfo(OpenFileDialog1.FileName)
            If fi.Extension.ToUpper = ".XLS" Then
                ' ...do something with "fi"...
                MessageBox.Show(fi.FullName, "Excel File Selected")
            End If
        End If