Gets or sets a filter string that specifies the files types and descriptions to display in the SaveFileDialog.
Assembly: System.Windows (in System.Windows.dll)
The filter string does not contain at least one vertical bar (|).
If the property is Empty, all files are displayed. Folders are always displayed.
consists of a description of the filter followed by a vertical bar (|) and the filter pattern. The filter can specify one or more file types.
The description describes the type of files shown in the dialog box. Although the description can be any string, it usually consists of the type of files included in the filter followed by the parentheses that contain the extensions associated with the description. The filter description appears in the Save as type drop-down list of the dialog box. The following is an example of a filter description.
My Files (*.my)
The filter pattern determines which files are shown by the dialog box. Filter patterns for the same description are separated by a semicolon (;). You can specify an exact match or use the wildcard character (*) in combination with the dot character (.) to specify file name or extension matches.
The following is an example of a filter description followed by multiple filter patterns. This example adds Image Files (*.bmp, *.jpg) to the Save as type drop-down list and shows .bmp and .jpg files when it is selected.
Image Files (*.bmp, *.jpg)|*.bmp;*.jpg
Multiple filter options are separated by the vertical bar.
The following is an example of multiple filter descriptions and patterns. This example adds Text Files (*.txt) and All Files (*.*) to the Save as type drop-down list. When Text Files (*.txt) is selected, .txt files are shown. When All Files (*.*) is selected, all file types are shown.
Text Files (*.txt)|*.txt|All Files (*.*)|*.*
Use the FilterIndex property to specify which filter appears first in the Save as type drop-down list. Otherwise, filter descriptions will appear in the order that they are listed in the value.
If the specified filter does not contain at least one vertical bar, an exception will occur.
The following code example shows how to use the property.
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.