The Filter property Description for the OpenFileDialog dialog box:
First explain an example, analyze the composition of the Filter property: "Excel File |*.xls", the preceding "Excel file" becomes a label, is a readable string, can be customized, "|*.xls" is a filter, representing the filter folder in the suffix named. xls file, "* "represents a string that matches the name of an Excel file.
OK, here are some of the things that we often use:
1. Filter is null or empty, indicating that all files are displayed and folders are always displayed
2. To filter a specific file, set the Filter property to "label |*. suffix", according to this format, the label can be customized, is a string, the suffix indicates you need to filter the file suffix, such as ". txt,. doc", etc.
3. Need to filter a variety of files, such as the need to filter picture files, but there are several suffixes of picture files, such as JPG, PNG, GIF, etc., when you need to filter these files, set the Filter property to "label |*.jpg;*.png;*.gif", Note: Only a few more suffixes are added to the filter, separated by semicolons with different suffixes
4. When you need to filter a variety of files, but not all of them listed at the same time, only the user through the drop-down list to select the desired file type, filter. In this case, you only need to set a few more filters, the Filter property is set as follows: "Label 1|*.jpg| label 2|. Png| label 3|. GIF ". Note: Use the ' | ' Between different filters Separated.
The Filter property is similar to a regular expression, try * to indicate a character that matches a file name, use the suffix name of ". suffix" to match files, by connecting suffixes (trial; Connecting different filters means file filtering by user selecting a suffix name
Private voidBtnupload_click (Objectsender, EventArgs e) { using(OpenFileDialog open =NewOpenFileDialog ()) {Open. MultiSelect=false; Open. Title="Open File"; Open. Filter="Picture |*.jpg;*.png;*.gif;*.jpeg;*.bmp"; if(Open. ShowDialog () = =DialogResult.OK) {} }}
C # File Filters Filter