Add reference system. Design. dll
// Select the file storage path
Dirbrowser olderbrowserdlg = new dirbrowser ();
If (folderbrowserdlg. showdialog () = dialogresult. OK)
{
Txtfilepath. Text = folderbrowserdlg. selectedpath;
}
//
Using system. Windows. Forms. design;
Using system. Windows. forms;
Using system;
// Select the file storage address in the pop-up dialog box.
Public class directoryselect: foldernameeditor
{
Private folderbrowser Fb = new folderbrowser ();
Private string fdescription = "choose directory ";
Private string freturnpath = string. empty;
Public String description
{
Set {fdescription = value ;}
Get {return fdescription ;}
}
Public String returnpath
{
Get {return freturnpath ;}
}
Public directoryselect ()
{
}
Private dialogresult rundialog ()
{
FB. Description = This. description;
FB. startlocation = folderbrowserfolder. mycomputer;
FB. Style = folderbrowserstyles. restricttosubfolders;
// | Folderbrowserstyles. restricttodomain;
Return FB. showdialog ();
}
Public dialogresult showdialog ()
{
Dialogresult DREs = dialogresult. None;
DREs = rundialog ();
If (DREs = dialogresult. OK)
This. freturnpath = FB. directorypath;
Else
This. freturnpath = string. empty;
Return DREs;
}
}
// Select the file storage address in the pop-up dialog box.
// Call
// Dirbrowser mydirbrowser = new dirbrowser ();
// If (mydirbrowser. showdialog ()! = Dialogresult. Cancel)
// MessageBox. Show (mydirbrowser. returnpath );
Public class dirbrowser: foldernameeditor
{
Folderbrowser Fb = new folderbrowser ();
Public String description
{
Set {_ description = value ;}
Get {return _ description ;}
}
Public String returnpath
{
Get {return _ returnpath ;}
}
Public dirbrowser (){}
Public dialogresult showdialog ()
{
FB. Description = _ description;
FB. startlocation = folderbrowserfolder. mycomputer;
Dialogresult r = FB. showdialog ();
If (r = dialogresult. OK)
_ Returnpath = FB. directorypath;
Else
_ Returnpath = string. empty;
Return R;
}
// Private string _ description = "choose directory ";
// Private string _ returnpath = string. empty;
Private string _ description = "select a folder ";
Private string _ returnpath = string. empty;
}