SaveFileDialog Class

Definition

Represents a common dialog that allows the user to specify a filename to save a file as. SaveFileDialog cannot be used by an application that is executing under partial trust.

public sealed class SaveFileDialog : Microsoft.Win32.FileDialog
Inheritance

Examples

The following example demonstrates how to create a SaveFileDialog and process the result.

// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".text"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process save file dialog box results
if (result == true)
{
    // Save document
    string filename = dlg.FileName;
}
' Configure save file dialog box
Dim dlg As New Microsoft.Win32.SaveFileDialog()
dlg.FileName = "Document" ' Default file name
dlg.DefaultExt = ".text" ' Default file extension
dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension

' Show save file dialog box
Dim result? As Boolean = dlg.ShowDialog()

' Process save file dialog box results
If result = True Then
    ' Save document
    Dim filename As String = dlg.FileName
End If

Remarks

The following figure shows a SaveFileDialog for Windows Vista.

Save As dialog box

Starting in Windows Vista, open and save file dialog boxes have a Favorite Links panel on the left side of the dialog box that allows the user to quickly navigate to a different location. These links are called custom places. Use the CustomPlaces property to set this list of links.

XAML Text Usage

You cannot declare this managed class in XAML.

Constructors

SaveFileDialog()

Initializes a new instance of the SaveFileDialog class.

Properties

CreatePrompt

Gets or sets a value indicating whether SaveFileDialog prompts the user for permission to create a file if the user specifies a file that does not exist.

OverwritePrompt

Gets or sets a value indicating whether SaveFileDialog displays a warning if the user specifies the name of a file that already exists.

Methods

OpenFile()

Creates a read-write file stream for the filename selected by the user using SaveFileDialog.

Reset()

Resets all SaveFileDialog properties to their default values.

CheckPermissionsToShowDialog() Inherited from CommonDialog
ShowDialog() Inherited from CommonDialog
ShowDialog(Window) Inherited from CommonDialog
Tag Inherited from CommonDialog
AddExtension Inherited from FileDialog
CheckFileExists Inherited from FileDialog
CheckPathExists Inherited from FileDialog
CustomPlaces Inherited from FileDialog
DefaultExt Inherited from FileDialog
DereferenceLinks Inherited from FileDialog
FileName Inherited from FileDialog
FileNames Inherited from FileDialog
FileOk Inherited from FileDialog
Filter Inherited from FileDialog
FilterIndex Inherited from FileDialog
HookProc(IntPtr, Int32, IntPtr, IntPtr) Inherited from FileDialog
InitialDirectory Inherited from FileDialog
OnFileOk(CancelEventArgs) Inherited from FileDialog
Options Inherited from FileDialog
RestoreDirectory Inherited from FileDialog
RunDialog(IntPtr) Inherited from FileDialog
SafeFileName Inherited from FileDialog
SafeFileNames Inherited from FileDialog
Title Inherited from FileDialog
ToString() Inherited from FileDialog
ValidateNames Inherited from FileDialog
Equals(Object) Inherited from Object
Equals(Object, Object) Inherited from Object
GetHashCode() Inherited from Object
GetType() Inherited from Object
MemberwiseClone() Inherited from Object
ReferenceEquals(Object, Object) Inherited from Object

Applies to