1. OpenFileDialog
Private voidOpenfiledialogbtn_click (Objectsender, System.EventArgs e) {OpenFileDialog OpenFileDialog=NewOpenFileDialog (); Openfiledialog.initialdirectory="C : \///Note that the path is written with a.Openfiledialog.filter ="text Files |*.*| C # files |*.cs| all Files |*.*"; Openfiledialog.restoredirectory=true; Openfiledialog.filterindex=1; if(Openfiledialog.showdialog () = =DialogResult.OK) {fName=Openfiledialog.filename; File FileOpen=NewFile (fName); Isfilehavename=true; richTextBox1.Text=Fileopen.readfile (); Richtextbox1.appendtext (""); }}
2. SaveFileDialog
#regionThe realization of SaveFileDialog { //string Localfilepath, Filenameext, NewFileName, FilePath; stringLocalfilepath =String.Empty; SaveFileDialog SaveFileDialog1=NewSaveFileDialog (); //Set File typeSavefiledialog1.filter ="xls files (*.xls) |*.txt| All Files (*. *) |*.*"; //Set file name:Savefiledialog1.filename = DateTime.Now.ToString ("YYYYMMDD") +"-"+"Asset Information report. xls"; //Set Default file type display orderSavefiledialog1.filterindex =2; //Save dialog box remembers the last Open directorySavefiledialog1.restoredirectory =true; //Click the Save button to enter if(Savefiledialog1.showdialog () = =DialogResult.OK) {//Get file pathLocalfilepath =saveFileDialog1.FileName.ToString (); //string filname = This.openFileDialog2.FileName; //get the file name without a path//Filenameext = localfilepath.substring (localfilepath.lastindexof ("\ \") + 1); //get file path, without file name//FilePath = localfilepath.substring (0, localfilepath.lastindexof ("\ \")); //add time to file name before//NewFileName = DateTime.Now.ToString ("yyyyMMdd") + Filenameext; //add characters to the file name//SaveFileDialog1.FileName.Insert (1, "Dameng"); //System.IO.FileStream fs = (System.IO.FileStream) savefiledialog1.openfile ();//Output File//fs output files with text or pictures, just look at the requirements } }
3.folderBrowserDialog
if (Folderbrowserdialog1.showdialog () = = DialogResult.OK) { string filename = folderbrowserdialog1.selectedpath; = filename; }
Http://www.xuejiehome.com/blread-1679.html
http://blog.csdn.net/pvfhv/article/details/6087400
Http://www.cnblogs.com/smile-wei/archive/2012/07/04/2575630.html
1. The OpenFileDialog control has the following basic properties
InitialDirectory |
Initial directory of the dialog box |
Filter |
The file filter to display in the dialog box, for example, "text file (*.txt) |*.txt| All Files (*. *) | | *.*" |
FilterIndex |
The index of the file filter selected in the dialog box, set to 1 if the first item is selected |
Restoredirectory |
Controls whether the dialog box restores the current directory before closing |
FileName |
The first file to display in a dialog box or the last selected file |
Title |
Characters that will be displayed in the title bar of the dialog box |
AddExtension |
Whether to add default extensions automatically |
Checkpathexists |
Checks whether the specified path exists before the dialog box returns |
DefaultExt |
Default name extension |
Dereferencelinks |
Whether to dereference a shortcut before returning from the dialog box |
ShowHelp |
Enable the Help button |
Validatenames |
Control dialog box checks if the file name does not contain invalid characters or sequences |
2. OpenFileDialog controls have the following common events
FileOk |
Events to be handled when the user taps the "open" or "save" button |
HelpRequest |
Events to be handled when the user taps the Help button |
Winform file Control-Go