C#下载文件时候弹出选择文件夹保存目录的代码

作者:网络 来源:佚名 更新时间:2008-05-07 13:27:49 点击:

//保存文件夹选择对话框引用
//添加引用system.design.dll   /
using system.windows.forms.design;

 

private void button4_click(object sender, system.eventargs e)
  {

   //选择文件的保存路径
   //添加窗体控件folderbrowserdialog1
   dirbrowser   olderbrowserdlg=new   dirbrowser(); 
     
   if (folderbrowserdialog1.showdialog()==dialogresult.ok)
   {
    textbox2.text = folderbrowserdialog1.selectedpath;
   }

  }

  #region 弹出保存文件夹选择窗口类
  //一般选择文件保存地址都用弹出对话框来进行选择
  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;
   }
  }

  //一般选择文件保存地址都用弹出对话框来进行选择
  //调用  
  //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   =   "请选择文件夹";    
   private   string   _returnpath   =   string.empty; 
  }

  #endregion