C # File Filters Filter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.