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"
...
DefaultExt
is the extension that will be used if the user selects a file name with no extension (atleast that's my understanding from reading the description from MSDN).
When the user of your application specifies a file name without an extension, the FileDialog appends an extension to the file name.
You may have to make bmp
the first item in the filter list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With