I am using SaveFileDialog to save an image.
The filter of the control is : PNG|*png;|GIF|*gif;|BMP|*bmp;|JPEG|*jpg;*jpeg;
However, if the extension is not typed in filename, it does not automatically add the extension.
I know that i can set a DefaultExt, however, I do not know how to handle this when it comes to selecting from multiple extensions.
The issue you have is that the filter you’re using isn’t correct according to the rules of
FileDialog.Filter(you’ve left out the.characters in the patterns). BeforeSaveFileDialogauto-adds the extension, it first validates the selected filter. In your case, this validation is failing; which is why the auto-addition isn’t working as you expect.Try the following filter:
An explicit
dialog.AddExtension = true;won’t hurt here although I believe that’s the default.