Reprinted from: http://www.cnblogs.com/zhlziliaoku/p/5241097.html
1. Select File with OpenDialog
OpenFileDialog dialog = new OpenFileDialog ();d ialog. MultiSelect = true;//This value determines whether multiple file dialog can be selected. Title = "Please select Folder";d ialog. Filter = "All Files (*. *) |*.*"; if (dialog. ShowDialog () = = System.Windows.Forms.DialogResult.OK) { string file = dialog. FileName;}
The Filter property is assigned a string to filter the file type, and the string is described as follows: ' | ' Split two, one is a comment, one is the real filter, and the comment is displayed. If you want to display files of more than one type at a time, separate them with semicolons. such as: open1.filter= "picture file (*.jpg,*.gif,*.bmp) |*.jpg;*.gif;*.bmp"; The filter file type is "|" *.jpg;*.gif;*.bmp Three types of files on the right, and the file type strings shown to the user in Opendialog/savedialog are: "|" image file (*.jpg,*.gif,*.bmp) to the left of the number. Again such as: open1.filter= "image file (*.jpg;*.jpg;*.jpeg;*.gif;*.png) |*.jpg;*.jpeg;*.gif;*.png";
2. Use System.Windows.Forms.FolderBrowserDialog to select folders
System.Windows.Forms.FolderBrowserDialog dialog =new System.Windows.Forms.FolderBrowserDialog ();d ialog. Description = "Please select txt folder"; if (dialog. ShowDialog () ==system.windows.forms.dialogresult.ok ) { if (string. IsNullOrEmpty (dialog. SelectedPath) { System.Windows.MessageBox.Show (this, "folder path cannot be empty", "hint"); return; } This. Loadingtext = "in process ..."; This. Loadingdisplay = true; Action<string> a = Daorudata; A.begininvoke (dialog. Selectedpath,asynccallback, a);}
3. Open a file or folder directly under a path
System.Diagnostics.Process.Start ("ExpLore", "C:\\window");
C # Select a file, select a folder, open a file (or a folder)