Reputation: 20800
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?
Upvotes: 5
Views: 8511
Reputation: 3696
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.
.
Upvotes: -1
Reputation: 23324
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.
Upvotes: 5
Reputation: 572
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();
Upvotes: 2
Reputation: 56727
It should work exactly as you wrote in your question:
dialog.Filter = "Image files|*.bmp;*.jpeg;*.jpg;*.png;*.gif"
Upvotes: 0