SaveFileDialog Class

Provides a dialog box that enables the user to specify options for saving a file.


Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

public sealed class SaveFileDialog

The SaveFileDialog type exposes the following members.

Public methodSaveFileDialogInitializes a new instance of the SaveFileDialog class.

Public propertyDefaultExtGets or sets the default file name extension applied to files that are saved with the SaveFileDialog.
Public propertyDefaultFileNameGets or sets the file name used if a file name is not specified by the user.
Public propertyFilterGets or sets a filter string that specifies the files types and descriptions to display in the SaveFileDialog.
Public propertyFilterIndexGets or sets the index of the selected item in the Save as type drop-down list.
Public propertySafeFileNameGets the file name for the selected file associated with the SaveFileDialog.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOpenFileOpens the file specified by the SafeFileName property.
Public methodShowDialog()Displays a SaveFileDialog that is modal to the Web browser or main window.
Public methodShowDialog(Window)Displays an SaveFileDialog that is modal to the specified window.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

This class enables the user to specify a file name and location to save a file.

The following illustration shows a an SaveFileDialog in a Silverlight running on Windows 7 and hosted in Internet Explorer.

Save File Dialog

Save file dialog box

You show a save dialog control using the ShowDialog method. For security purposes Silverlight file and print dialogs must be user-initiated. This means you must show them from a user-initiated action such as the click event handler for a button. In addition, there is a limit on the time allowed between when the user initiates the dialog and when the dialog is shown. If the time limit between these actions is exceeded, an exception will occur.

You can optionally specify a filter for the dialog box by using the Filter property. If no filter is specified, you can set the default file name extension applied to files in the dialog box by using the DefaultExt property.

If you attempt to show the dialog box from KeyDown event handlers and other synchronous calls to application code, such as LayoutUpdated or SizeChanged event handlers, an exception will be thrown. An exception will not be thrown when the application is hosted in Internet Explorer, running in protected mode.


If you want to save data for an application, you can use isolated storage. For more information, see IsolatedStorageFile.


The Silverlight plug-in does not support SaveFileDialog in full-screen mode. In most cases, displaying the dialog box in full-screen mode will cause the plug-in to revert to embedded mode. However, to avoid issues on some browsers, you should exit full-screen mode before using these classes.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 StackFrame is not supported in Silverlight for Windows Phone.

The following code example shows how to use the SaveFileDialog.

SaveFileDialog textDialog;
public Page()
    textDialog = new SaveFileDialog();
    textDialog.Filter = "Text Files | *.txt";
    textDialog.DefaultExt = "txt";

private void button1_Click(object sender, RoutedEventArgs e)
    bool? result = textDialog.ShowDialog();
    if (result == true)
        System.IO.Stream fileStream = textDialog.OpenFile();
        System.IO.StreamWriter sw = new System.IO.StreamWriter(fileStream);
        sw.WriteLine("Writing some text in the file.");

<Grid x:Name="LayoutRoot" Background="White">
     <Button Height="100" Width="100" Content="Save Text File" x:Name="button1" 
        Click="button1_Click"  />


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.