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;