I have a problem with the save file dialog. The save file dialog looks fine until I change the save as type in the file dialog. It always add the extension that already exists. I need to have the multidot extenstion.
So, if I change the save as type, the save file dialog will make the filename become D:\Temp\Test.dt.dt.dt.dt.dt.dt.txt
How to make the file the .dt not added when I switch the save as type
Is this a windows bug ? I am using winform and .net3.5 Here is how I reproduce it:
public partial class Form1 : Form
{
  public Form1()
  {
    InitializeComponent();
  }
  private void button1_Click( object sender, EventArgs e )
  {
    SaveFileDialog saveFileDialog1 = new SaveFileDialog
                             {
                               Title = "Save list file",
                               Filter =  "Text Files (*.dt.txt)|*.dt.txt|Microsoft Excel Files (*.dt.xls)|*.dt.xls|Microsoft Excel XML Files (*.dt.xlsx)|*.dt.xlsx",
                               DefaultExt = ".dt.txt",
                               OverwritePrompt = true,
                               SupportMultiDottedExtensions = true,
                               AddExtension = true
                             };
    saveFileDialog1.FileName = "D:\\Temp\\test.dt.txt";
    saveFileDialog1.ShowDialog();
  }
}
 
                        
I think the problem is in FileDialog.cs:line877. It calls
string currentExtension = Path.GetExtension(fileName);to get current extension of selected file and here is the code forPath.GetExtension(fileName);that does not support multi dotted extension. so I think this is a bug.