[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
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)
Visual Basic (Declaration)
Public NotInheritable Class SaveFileDialog
Dim instance As SaveFileDialog
public sealed class SaveFileDialog
This class enables the user to specify a file name and location to save a file. 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.
Note: |
|---|
If you want to save data for an application, you can use isolated storage. For more information, see IsolatedStorageFile. |
Note: |
|---|
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. |
The following code example shows how to use the SaveFileDialog.
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
SaveFileDialog textDialog;
public Page()
{
InitializeComponent();
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.");
sw.Flush();
sw.Close();
}
}
<Grid x:Name="LayoutRoot" Background="White">
<Button Height="100" Width="100" Content="Save Text File" x:Name="button1"
Click="button1_Click" />
</Grid>
System..::.Object
System.Windows.Controls..::.SaveFileDialog
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Reference