现在的位置: 首页 > 综合 > 正文

取得文件目录代码

2013年10月18日 ⁄ 综合 ⁄ 共 746字 ⁄ 字号 评论关闭
using System.Windows.Forms.Design;

public class openFile:FolderNameEditor
 {
  FolderBrowser fb = new FolderBrowser();  
   public DialogResult DisplayDialog()
   {
    return DisplayDialog("请选择一个文件夹");
   }
   public DialogResult DisplayDialog(string description)
   {
    fb.Description=description;
    return fb.ShowDialog();
   }
   public string Path
   { 
    get{return fb.DirectoryPath;}
   }
   ~openFile()
   {
    fb.Dispose();
   }   
 }

openFile openFolder = new openFile();
   if (openFolder.DisplayDialog()==DialogResult.OK)
    textBox1.Text=openFolder.Path.ToString();
   else
    textBox1.Text="你没有选择目录";

这只能取得目录,不能取得文件,以后再加。

OpenFileDialog ofd = new OpenFileDialog();
   ofd.Filter="txt files (*.txt)|*.txt|All files(*.*)|*.*|doc files(*.doc)|*.doc";
   ofd.ShowDialog();
   ofd.FileName;

抱歉!评论已关闭.