Ace McCloud
Ace McCloud

Reputation: 900

file filter in open file dialog

I would like to add some checks to my OpenFileDialog to show All files except .exe and .jar.

  var openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                Title = @"Upload File",
                Filter =
                    @"All Files|*.*|Text File (.txt)|*.txt|Word File (.docx ,.doc)|*.docx;*.doc|PDF (.pdf)|*.pdf|Spreadsheet (.xls ,.xlsx)|  *.xls ;*.xlsx|Presentation (.pptx ,.ppt)|*.pptx;*.ppt",
                FilterIndex = 1,
                RestoreDirectory = true
            };

The all files options allows All files . Not just all files of the type specified after . If the user selects one type , ssay .txt from the drop down , the other files are not shown. But the all files option shows ALL files including exe and jar.

I want to implement an option where I specifiy 5 file types , like above , and the All files option simply shows all the 5 file types together instead of ALL file types.

Upvotes: 1

Views: 7676

Answers (1)

schroeder
schroeder

Reputation: 153

Since the filter for All Files is *.* all file types are shown, naturally... You can work around by specifying the filter for All Files like

Filter = @"All Files|*.txt;*.docx;*.doc;*.pdf*.xls;*.xlsx;*.pptx;*.ppt|Text File (.txt)|*.txt|Word File (.docx ,.doc)|*.docx;*.doc|PDF (.pdf)|*.pdf|Spreadsheet (.xls ,.xlsx)|  *.xls ;*.xlsx|Presentation (.pptx ,.ppt)|*.pptx;*.ppt"

Upvotes: 3

Related Questions