FileDialog::Filter Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the filter string that determines what types of files are displayed from either the OpenFileDialog or SaveFileDialog.

Namespace:   Microsoft.Win32
Assembly:  PresentationFramework (in PresentationFramework.dll)

public:
property String^ Filter {
	String^ get();
	void set(String^ value);
}

Property Value

Type: System::String^

A 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 null or Empty, all files are displayed, and folders are always displayed.

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.

Using the FileDialog.Filter in the Open Dialog Box

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.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top
Show: