C#获取文件夹对话框
来源:互联网 发布:工作的意义 知乎 编辑:程序博客网 时间:2024/06/03 19:38
首先要说明一下:
添加引用: System.Design
此文件在下面的位置
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Design.dll
有些人说在添加引用的面板中并找不到这个引用.这是由于你的目标框架设置错误
在 解决方案管理器上 右键 "属性" --> 应用程序 --> 目标框架 修改为 .Net Framework 4.0 (没有那个client )
这样你再在添加引用面板中就可以找到这个引用了.
添加这两个引用
using System.Windows.Forms;
using System.Windows.Forms.Design;
==================新建一个FolderDialog类 ==============
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
public class FolderDialog : FolderNameEditor
{
FolderNameEditor.FolderBrowser fDialog = new FolderNameEditor.FolderBrowser();
public FolderDialog()
{
}
public DialogResult DisplayDialog()
{
return DisplayDialog("请选择一个文件夹");
}
public DialogResult DisplayDialog(string description)
{
fDialog.Description = description;
return fDialog.ShowDialog();
}
public string Path
{
get { return fDialog.DirectoryPath; }
}
~FolderDialog() { fDialog.Dispose(); }
}
--------------调用--------------------
FolderDialog openFolder = new FolderDialog();
if (openFolder.DisplayDialog() == DialogResult.OK)
{
textBox1.Text = openFolder.Path.ToString();
}
else
{
textBox1.Text = "你没有选择目录";
}
DirectoryInfo dirInfo = new DirectoryInfo(textBox1.Text);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo filename in files)
{
listBox1.Items.Add(filename);
}
===================打开指定的文件夹路径===================
string openPath = @“C:\test\demo”;
if (Directory.Exists(openPath))
System.Diagnostics.Process.Start(openPath);
else
MessageBox.Show("打开的文件路径无效");
===================打开指定文件的路径======================
string openPath = @"H:\test\Data\userSys.cs";
if (File.Exists(openPath))
System.Diagnostics.Process.Start(openPath);
else
MessageBox.Show("指定文件不存在");
- C#获取文件夹对话框
- 网络资源--获取C#浏览文件夹对话框(zz)
- 用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- WinForm C#获取浏览文件夹对话框
- 【转】用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- 用C#获取浏览文件夹对话框
- C# 文件对话框,文件夹对话框使用
- C#选取文件夹的对话框
- C# 文件对话框选择文件夹
- C#实现选择文件夹对话框
- C#打开文件、文件夹对话框
- C#获取特殊文件夹
- C# 获取系统文件夹
- hdu2398 Savings Account - 数学
- C++中你必须知道的23种算法
- SQL基础2
- Asp.net中DataGrid控件的自定义分页
- 编程之美2013 资格赛第二题 长方形
- C#获取文件夹对话框
- hadoop核心逻辑shuffle代码分析-map端
- 硕士、博士论文写作几大自动编号功能(一)
- Linux常用命令
- iOS NSInvocation用法
- 移动应用被苹果拒绝上架的9个意外原因
- 50个c/c++ 源代码网站
- 面试体会二:面向对象之多态(一、理论知识)
- 应届毕业生学java