C# Don't display filter extensions in OpenFileDialog

Mircea Ispas picture Mircea Ispas · Jan 10, 2012 · Viewed 7.6k times · Source

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?

Answer

Henrik picture Henrik · Jan 10, 2012

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.