Search code examples
c#.netsavefiledialog

Multiple types in a SaveFileDialog filter


In my SaveFileDialog I have multiple types in the filter, however when viewing the dialog if I choose a filter to view files of that type in the directory I am only able to see files for the first and last filters.

    bool save;
    SaveFileDialog dlg = new SaveFileDialog();
    dlg.FileName = "*";
    dlg.DefaultExt = "bmp";
    dlg.ValidateNames = true;

    dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png |Tiff Image (.tiff)|*.tiff |Wmf Image (.wmf)|*.wmf";
    save = (bool)dlg.ShowDialog();

    if (save)
    {
        SaveImage(dlg.FileName);
    }

I can see files of type .bmp and .wmf If I change the order of the filters I can always only see the first and last.


Solution

  • Remove the spaces after the file type:

    dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf";