Provides a dialog box that enables the user to specify options for saving a file.
Assembly: System.Windows (in System.Windows.dll)
Thetype exposes the following members.
|DefaultExt||Gets or sets the default file name extension applied to files that are saved with the .|
|DefaultFileName||Gets or sets the file name used if a file name is not specified by the user.|
|Filter||Gets or sets a filter string that specifies the files types and descriptions to display in the .|
|FilterIndex||Gets or sets the index of the selected item in the Save as type drop-down list.|
|SafeFileName||Gets the file name for the selected file associated with the .|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|OpenFile||Opens the file specified by the SafeFileName property.|
|ShowDialog||Displays a that is modal to the Web browser or main window.|
|ShowDialog(Window)||Displays an that is modal to the specified window.|
|ToString||Returns 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 in a Silverlight running on Windows 7 and hosted in Internet Explorer.
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 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.
Silverlight for Windows PhoneStackFrame is not supported in Silverlight for Windows Phone.
The following code example shows how to use the .
Private textDialog As SaveFileDialog Public Sub New() InitializeComponent() textDialog = New SaveFileDialog() textDialog.Filter = "Text Files | *.txt" textDialog.DefaultExt = "txt" End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim result As System.Nullable(Of Boolean) = textDialog.ShowDialog() If result = True Then Dim fileStream As System.IO.Stream = textDialog.OpenFile() Dim sw As New System.IO.StreamWriter(fileStream) sw.WriteLine("Writing some text in the file.") sw.Flush() sw.Close() End If End Sub
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.