Friday 5 December 2014

Save File Dialog in WPF (Microsoft.Win32.SaveFileDialog)


The following code example shows a quick way on how to use the Microsoft.Win32.SaveFileDialog namespace within WPF to show the SaveFileDialog.

Code Snippet
  1. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  2. dlg.FileName = "Image"; // Default file name
  3. dlg.DefaultExt = ".bmp"; // Default file extension
  4. dlg.Filter = "Bitmap File (.bmp)|*.bmp"; // Filter files by extension
  5.  
  6. // Show save file dialog box
  7. Nullable<bool> result = dlg.ShowDialog();
  8.  
  9. // Process save file dialog box results
  10. if (result == true)
  11. {
  12.     // Use filename here if required!
  13.     string filename = dlg.FileName;
  14. }
End of Code Snippet

No comments: