title: System.Windows.Forms.SaveFileDialog does not enforce default extension
body: <p>I am trying to make <code>SaveFileDialog</code> and <code>FileOpenDialog</code> enforce an extension to the file name entered by the user. I've tried using the sample proposed in <a href="https://stackoverflow.com/questions/389070/how-does-the-addextension-property-work-in-c-2-0">question 389070</a> but it does not work as intended:</p>
  
  <pre><code>var dialog = new SaveFileDialog())
  
  dialog.AddExtension = true;
  dialog.DefaultExt = "foo";
  dialog.Filter = "Foo Document (*.foo)|*.foo";
  
  if (dialog.ShowDialog() == DialogResult.OK)
  {
      ...
  }
  </code></pre>
  
  <p>If the user types the text <code>test</code> in a folder where a file <code>test.xml</code> happens to exist, the dialog will suggest the name <code>test.xml</code> (whereas I really only want to see <code>*.foo</code> in the list). Worse: if the user selects <code>test.xml</code>, then I will indeed get <code>test.xml</code> as the output file name.</p>
  
  <p>How can I make sure that <code>SaveFileDialog</code> really only allows the user to select a <code>*.foo</code> file? Or at least, that it replaces/adds the extension when the user clicks <code>Save</code>?</p>
  
  <p>The suggested solutions (implement the <code>FileOk</code> event handler) only do part of the job, as I really would like to disable the <code>Save</code> button if the file name has the wrong extension.</p>
  
  <p>In order to stay in the dialog <em>and</em> update the file name displayed in the text box in the <code>FileOk</code> handler, to reflect the new file name with the right extension, see the <a href="https://stackoverflow.com/questions/1599511/how-to-replace-filename-in-savefiledialog-fileok-event-handler">following related question</a>.</p>