How can I use multiple file extensions within one group using OpenFileDialog
?
I have Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg|PNG|*.png|TIFF|*.tiff"
and I want to create groups so JPG are *.jpg and *.jpeg, TIFF are *.tif and *.tiff and also 'All graphic types'? How can I do that?
Asked
Active
Viewed 1.5e+01k times
144

Ichibann
- 4,371
- 9
- 32
- 39
3 Answers
269
Try:
Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff"
Then do another round of copy/paste of all the extensions (joined together with ;
as above) for "All graphics types":
Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|"
+ "All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff"

user541686
- 205,094
- 128
- 528
- 886
-
9I would suggest putting the "ALL" option first, as that what seems to be the default. – John Grabanski Nov 22 '16 at 20:44
-
Don't put a `|` in the description part, it will miss-parse it. – CAD bloke Jul 14 '20 at 23:04
78
This is from MSDN sample:
(*.bmp, *.jpg)|*.bmp;*.jpg
So for your case
openFileDialog1.Filter = "JPG (*.jpg,*.jpeg)|*.jpg;*.jpeg|TIFF (*.tif,*.tiff)|*.tif;*.tiff"

Saeed Amiri
- 22,252
- 5
- 45
- 83
-
2This solution is more elegant, correct and desired. This should be the most up-voted solution. – Dr. Cogent Feb 28 '17 at 14:22
1
Based on First answer here is the complete image selection options:
Filter = @"|All Image Files|*.BMP;*.bmp;*.JPG;*.JPEG*.jpg;*.jpeg;*.PNG;*.png;*.GIF;*.gif;*.tif;*.tiff;*.ico;*.ICO
|PNG|*.PNG;*.png
|JPEG|*.JPG;*.JPEG*.jpg;*.jpeg
|Bitmap(.BMP,.bmp)|*.BMP;*.bmp
|GIF|*.GIF;*.gif
|TIF|*.tif;*.tiff
|ICO|*.ico;*.ICO";

JharPaat
- 321
- 1
- 2
- 12