Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


OpenFileDialog.Filter not filtering properly except All files (*.*)?

Posted on 2006-04-13
Medium Priority
Last Modified: 2012-06-27
I am writing an application in Visual Basic .NET 2003, and am having trouble with the filter for the OpenFileDialog.  When I run the app and run the form to bring up the OpenFileDialog, it will not show any files with a *.htm or *.html.  But, if I choose the "All Files", it shows everything.  How come, if I choose the "HTML Pages" filter, it does not work?  Here is my code snippet:

    Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
        ' Declare OpenFileDialog object
        Dim objOpenFileDialog As New OpenFileDialog

        ' Set the OpenFileDialog properties
        With objOpenFileDialog
            .Filter = "HTML Pages (*.htm; *.html) | *.htm; *.html | All files (*.*) | *.*"
            .FilterIndex = 1
            .InitialDirectory = "C:\"
            .Title = "Open Webpage"
        End With

        ' Show the dialog
        If objOpenFileDialog.ShowDialog = DialogResult.OK Then
            ' If the Open button was clicked, then load the file name selected
            txtOpenFile.Text = objOpenFileDialog.FileName
        End If

        ' Cleanup
        objOpenFileDialog = Nothing
    End Sub
Question by:pepsi_cola
LVL 43

Accepted Solution

TimCottee earned 2000 total points
ID: 16445887
Hi pepsi_cola,

>             .Filter = "HTML Pages (*.htm; *.html) |*.htm;*.html | All files (*.*) | *.*"

You had spaces preceding the *.htm and *.html so unless your files started with a space there would be no match

Tim Cottee

Author Comment

ID: 16445939
Its amazing what a space can do to mess everything up.  Thanks!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question