Skip to content

CommonFileDialog.FileName property changes extension back to default #18

@BradSmith1985

Description

@BradSmith1985

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions