5
votes

I have multiple extensions in the Filter property of OpenFileDialog. Is possible to hide the extensions and show only the description?

Sample:

dialog.Filter = "Image files|*.bmp;*.jpg; many image file extensions here"

I want to show only the text: "Image files" in the file type combo box because the extension string is very long. Is this possible?

4

4 Answers

5
votes

This

dialog.Filter = "Image files (*.bmp)|*.bmp;*.jpg"

will only display "Image files (*.bmp)" in the combo box while still showing files with all the specified extensions.

Or you could do

dialog.Filter = "Image files (*.bmp;...)|*.bmp;*.jpg"

to indicate that it looks for files with extension bmp and some other extensions.

This might depend on the OS. I tested with Windows 7.

2
votes

This should work:

    dialog.Filter = "All Supported Audio | *.mp3; *.wma | MP3s | *.mp3 | WMAs | *.wma";
    dialog.AutoUpgradeEnabled = false; //using FileDialog.AutoUpgradeEnabled = false it will display the old XP sytle dialog box, which then displays correctly
    dialog.ShowDialog();
0
votes

It should work exactly as you wrote in your question:

dialog.Filter = "Image files|*.bmp;*.jpeg;*.jpg;*.png;*.gif"
-1
votes

It is very simple, you know. See the following code snippet. It will run perfectly. You can define more file-types like this way.

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|BMP Files(*.bmp)|*.bmp|GIF Files(*.gif)|*.gif|TIFF Files(*.tiff)|*.tiff|All Files(*.*)|*.*";

There are two parts in the Filter property. "JPG Files(.jpg)|.jpg" means the dropdown for selecting file-types will show "JPG Files(*.jpg)" and the filter will happen against the next part of pipe character i.e. *.jpg.

Note: Never use any space after *.jpg or be it any other file-type. If used, it cannot filter your desired file-type.

.