SaveFileDialog令人惊讶地添加了文件扩展名

时间:2017-02-23 10:33:25

标签: c# winforms savefiledialog

当我选择文件名" image.mgm"时,对话框System.Windows.Forms.SaveFileDialog 令人惊讶添加扩展名.BMP并返回" 图像。 mgm.BMP "通过属性FileName。 对于" image.png"

,它不会发生

几个样本:

  • image.bmp ==> image.bmp
  • image.png ==> image.png
  • image.mgm ==>的 image.mgm.BMP
  • image.MGM ==> image.MGM

如何修复意外(对我来说)行为?

样本来源可以在github上找到:https://github.com/constructor-igor/TechSugar/tree/master/WinForm/FileSaveDialogIssue/FileSaveDialogIssue

UPD 附加事实:当我添加键" HKEY_CLASSES_ROOT.mgm"到注册表,"文件对话框"停止添加" .BMP"到.mgm

        public Form1()
    {
        InitializeComponent();
        this.saveFileDialog.AddExtension = false;
    }

    private void btnOpenFile_Click(object sender, EventArgs e)
    {
        saveFileDialog.Title = @"Save calculated image";
        saveFileDialog.FileName = "noname.tiff";
        saveFileDialog.Filter = @"My Files(*.BMP;*.MGM;*.PNG)|*.BMP;*.MGM;*.PNG|All files (*.*)|*.*";
        if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
        {
            MessageBox.Show(String.Format("File name {0}", saveFileDialog.FileName));
        }
    }

0 个答案:

没有答案