This article mainly introduces C # using the browse button to obtain the file path and folder path method, combined with the instance form analysis of C # Browser event response and file operation related skills, the need for friends can refer to the following
This example describes how C # uses the browse button to get the file path and folder path. Share to everyone for your reference, as follows:
Generate Folder path
private void Btnchoose_click (object sender, EventArgs e) { using (openfiledialog Dialog = new OpenFileDialog ()) { dialog. MultiSelect = true; if (dialog. ShowDialog () = = DialogResult.OK) { try { this.tbFilePath.Text = dialog. FileName; } catch (Exception ex) { throw (ex); } } }
Generate File path
Create a new Folderdialog class (overloaded Foldernameeditor)
Using system;using system.collections.generic;using system.linq;using system.text;using System.Windows.Forms.Design ; using System.windows.forms;namespace common{ class Folderdialog:foldernameeditor { FolderBrowser fdialog = new FolderBrowser (); Public Folderdialog () {} public DialogResult Displaydialog () { return displaydialog ("Please select a folder"); } Public DialogResult Displaydialog (string description) { fdialog.description = description; return Fdialog.showdialog (); } public string Path { get { return fdialog.directorypath; } } ~folderdialog () { fdialog.dispose ();}} }
Events under the Browse button
private void Btnchoose_click (object sender, EventArgs e) { Folderdialog fdialog = new Folderdialog (); Fdialog.displaydialog (); This.tbfilePath.Text = Fdialog.path;}