Describe the bug
The FileName property on CommonFileDialog erroneously changes the file extension when the DefaultExtension property is set.
To Reproduce
using (var dlg = new CommonSaveFileDialog()) {
dlg.Filters.Add(new CommonFileDialogFilter("Word Document", "docx"));
dlg.Filters.Add(new CommonFileDialogFilter("Adobe PDF", "pdf"));
dlg.DefaultExtension = "docx";
// when dialog opens, user enters "test.docx" and then changes file type to "pdf"
// dialog correctly updates filename to "test.pdf"
if (dlg.ShowDialog(owner) == CommonFileDialogResult.Ok) {
string wrongFileName = dlg.FileName; // value is "test.docx", WRONG
}
}
Expected behavior
If the filename has no extension, it should be changed to DefaultExtension.
If the filename has an extension that does not match SelectedFileTypeIndex, it should be changed accordingly.
If the filename already has the correct extension, the property accessor should NOT change it.
Describe the bug
The
FileNameproperty onCommonFileDialogerroneously changes the file extension when theDefaultExtensionproperty is set.To Reproduce
Expected behavior
If the filename has no extension, it should be changed to
DefaultExtension.If the filename has an extension that does not match
SelectedFileTypeIndex, it should be changed accordingly.If the filename already has the correct extension, the property accessor should NOT change it.