Gets or sets the filter string that determines what types of files are displayed from either the OpenFileDialog or SaveFileDialog.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: Not mapped to an xmlns.
Public Property Filter As String
Get
Setpublic string Filter { get; set; }public:
property String^ Filter {
String^ get ();
void set (String^ value);
}member Filter : string with get, set
<object Filter="string" .../>Property Value
Type: SystemA String that contains the filter. The default is Empty, which means that no filter is applied and all file types are displayed.
| Exception | Condition |
|---|---|
| ArgumentException | The filter string is invalid. |
If Filter is either
You can specify a subset of file types to be displayed by setting the Filter property. Each file type can represent a specific type of file, such as the following:
Word Documents (*.doc)
Excel Worksheets (*.xls)
PowerPoint Presentations (*.ppt)
Alternatively, a file type can represent a group of related file types, such as the following:
Office Files (*.doc, *.xls, *.ppt)
All Files (*.*)
To specify a subset of the types of files that are displayed, you set the Filter property with a string value (the filter string) that specifies one or more types of files to filter by. The following shows the expected format of the filter string:
FileType1[[|FileType2]...[|FileTypeN]]
You use the following format to describe each file type:
Label|Extension1[[;Extension2]...[;ExtensionN]]
The Label part is a human-readable string value that describes the file type, such as the following:
"Word Documents"
"Excel Worksheets"
"PowerPoint Presentations"
"Office Files"
"All Files"
Each file type must be described by at least one Extension. If more than one Extension is used, each Extension must be separated by a semicolon (";"). For example:
"*.doc"
"*.xls;"
"*.ppt"
"*.doc;*.xls;*.ppt"
"*.*"
The following are complete examples of valid Filter string values:
Word Documents|*.doc
Excel Worksheets|*.xls
PowerPoint Presentations|*.ppt
Office Files|*.doc;*.xls;*.ppt
All Files|*.*
Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt|Office Files|*.doc;*.xls;*.ppt|All Files|*.*
Each file type that is included in the filter is added as a separate item to the Files of type: drop-down list in the OpenFileDialog or SaveFileDialog, as shown in the following figure.
.png)
The user can choose a file type from this list to filter by. By default, the first item in the list (for example, the first file type) is selected when the OpenFileDialog or SaveFileDialog is displayed. To specify that another file type to be selected, you set the FilterIndex property before showing the OpenFileDialog or SaveFileDialog (by calling ShowDialog).
The following examples demonstrate several types of filter strings that can be set by using the Filter property.
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Show all files
dlg.Filter = String.Empty
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Show all files
dlg.Filter = string.Empty;
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Show all files
dlg.Filter = Nothing
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Show all files
dlg.Filter = null;
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by Word Documents
dlg.Filter = "Word Documents|*.doc"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by Word Documents
dlg.Filter = "Word Documents|*.doc";
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by Excel Worksheets
dlg.Filter = "Excel Worksheets|*.xls";
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by PowerPoint Presentations
dlg.Filter = "PowerPoint Presentations|*.ppt";
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by Office Files
dlg.Filter = "Office Files|*.doc;*.xls;*.ppt";
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by All Files
dlg.Filter = "All Files|*.*"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by All Files
dlg.Filter = "All Files|*.*";
dlg.ShowDialog();
Imports Microsoft.Win32
...
Dim dlg As New OpenFileDialog()
' Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations
' OR Office Files
' OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" & "|Office Files|*.doc;*.xls;*.ppt" & "|All Files|*.*"
dlg.ShowDialog()
using Microsoft.Win32;
...
OpenFileDialog dlg = new OpenFileDialog();
// Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations
// OR Office Files
// OR All Files
dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
"|Office Files|*.doc;*.xls;*.ppt" +
"|All Files|*.*";
dlg.ShowDialog();
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.