var dlg = new SaveFileDialog();
dlg.FileName = "graph";
dlg.DefaultExt = ".bmp";
dlg.Filter = "PNG|*.png|DOT|*.dot|Windows Bitmap Format|*.bmp|GIF|*.gif|JPEG|*.jpg|PDF|*.pdf|Scalable Vector Graphics|*.svg|Tag Image File Format|*.tiff";
The extension always defaults to .png
. It seems the DefaultExt
is ignored if there is a Filter
; then it just defaults to the first option in the list.
Is there a way to force it to actually respect the default ext?
I'm a few years too late, but coincidentally, I found a solution to the problem while looking at the code from this question.
There he specified the extension without a .
. I then looked into the microsoft documentation. In the example the DefaultExt
was also specified without a .
.
If DefaultExt
is specified with a .
, FileDialog
will automatically choose the first extension of the filter.
DefaultExt
should be set to the extension without a .
.
Meaning that in your example dlg.DefaultExt = ".bmp";
you need to change ".bmp"
to "bmp"
...