File path and folder path methods obtained using the browse button in C #

Source: Internet
Author: User
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;}
Related Article

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.