A lightweight fluent builder that easily creates file filter strings used in the various WinForms and WPF file dialogs.
The various file dialogs in WinForms (OpenFileDialog / SaveFileDialog) and WPF (OpenFileDialog / SaveFileDialog) all use file filter strings to control how they filter files. These strings are set in the Filter
property of the various dialogs.
File filter strings are described as follows:
For each filtering option, the filter string contains a description of the filter, followed by the vertical bar (|) and the filter pattern. The strings for different filtering options are separated by the vertical bar.
Here are some example file filter strings:
Text files (*.txt)|*.txt|All files (*.*)|*.*
Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*
PM> Install-Package FluentFileFilterBuilder
The first example filter string described above can be created as so:
var filter = new FileFilterBuilder()
.Add("Text files", "txt")
.Add("All files", "*")
.ToString();
The second example filter string described above can be created as so:
var filter = new FileFilterBuilder()
.Add("Image files", "BMP", "JPG", "GIF")
.Add("All files", "*")
.ToString();
FluentFileFilterBuilder is distributed under the MIT license.