Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. text; using System. windows. forms; namespace TestFolderBrowserDialog {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void btnFile_Click (object sender, EventArgs e) {OpenFileDialog fileDialog = new OpenFileDialog (); fileDialog. multiselect = true; fileDialog. title = "select file"; fileDialog. filter = "all files (*. *) | *. * "; if (fileDialog. showDialog () = DialogResult. OK) {string file = fileDialog. fileName; MessageBox. show ("selected files:" + file, "SELECT file prompt", MessageBoxButtons. OK, MessageBoxIcon. information) ;}} private void btnPath_Click (object sender, EventArgs e) {FolderBrowserDialog dialog = new FolderBrowserDialog (); dialog. description = "select the file path"; if (dialog. showDialog () = DialogResult. OK) {string foldPath = dialog. selectedPath; MessageBox. show ("selected folder:" + foldPath, "select folder prompt", MessageBoxButtons. OK, MessageBoxIcon. information) ;}} private void btnOpen_Click (object sender, EventArgs e) {System. diagnostics. process. start ("assumer.exe", "c :\\ windows ");}}}
Description of the Filter attribute in the OpenFileDialog dialog box:
First, describe an example to analyze the composition of the Filter attribute: "Excel file | *. "xls", the previous "Excel file" becomes a tag and is a readable string that can be customized. "| * .xls is a file suffixed with .xls in the folder, and" * "indicates a string that matches the Excel file name.
OK. The following describes the situations that we often use:
1. If Filter is null or Empty, all files are displayed and folders are always displayed.
2. You need to Filter specific files and set the Filter attribute to "tag | * tags ".
3. you need to filter multiple files. For example, you need to filter image files, but there are several suffixes of image files, such as jpg, png, and gif. When you need to filter these files at the same time, set the Filter attribute to "tag | *. jpg ;*. png ;*. gif ", Note: Only a few suffixes are added to the filter, and different suffixes are separated by semicolons.
4. When you need to filter multiple files, but not all of them are listed at the same time, you only need to select the desired file type from the drop-down list. In this case, you only need to set several filters. The filter attribute is set as follows: "tag 1 | *. jpg | tag 2 |. png | tag 3 |. gif ". Note: Use "|" to separate different filters.
The Filter attribute is similar to a regular expression. * indicates the character that matches the file name. suffix "matches the suffix of the file. by connecting the suffix (trial; Separate the required suffix), all files with the suffix are filtered at the same time, use "|" to connect different filters to filter files by selecting suffix names.
Reprinted: http://blog.csdn.net/luxin10/article/details/6106898
Http://www.cnblogs.com/szytwo/archive/2012/03/21/2410041.html