SaveFileDialog
Prompts the user to select a location for saving a file on the server.
This class can either open and overwrite an existing file or create a new file.
Most of the functionality for this class is found in the FileDialog
class.
Features
Filtering
The SaveFileDialog filters files shown to the user based on a given pattern. For example, the filter Image Files|*.jpg|All files|*.*
will show files ending with .jpg by default. Users can modify the filter using the dropdown menu.

The FileDialog.FileName property returns the virtual path relative to the root. To get the physical path on the server, use FileDialog.MapPath().
Check Existing Files
The SaveFileDialog validates file existence before saving to disk, helping prevent accidental file overwrites.

Help
The SaveFileDialog includes an optional "?" (Help) tool for displaying navigation assistance.

How To
Connect to the File System
Add at least one IFileSystemProvider
to the Roots collection before showing the dialog:
//Using an absolute file path
SaveFileDialog filedialog = new SaveFileDialog();
filedialog.Roots.Add(new FileSystemProvider("C:\\", "Main_Directory"));
//Using a relative file path
SaveFileDialog filedialog = new SaveFileDialog();
filedialog.Roots.Add(new FileSystemProvider("./", "Main_Directory"));
Customize the Appearance
The SaveFileDialog supports customization of individual controls including textboxes and pickers.
To customize these controls:
Create a class inheriting from
FileDialogUI
Add the custom
FileDialog
constructorModify the controls as needed
public class CustomSaveFileDialogUI : FileDialogUI
{
public CustomSaveFileDialogUI(SaveFileDialog saveFileDialog) : base(saveFileDialog)
{
this.HeaderBackColor = Color.DarkOrange;
foreach (ColumnHeader col in this.listView.Columns)
{
col.BackColor = Color.DarkOrange;
}
}
}
After applying the OpenFileDialog's DialogTemplate
property to the new class, the result looks like this:

For advanced customization of the SaveFileDialog
using custom templates, see below.
Last updated
Was this helpful?