C# 选择文件 和 选择文件夹 对话框
2016-03-22 22:45
453 查看
<pre name="code" class="csharp"> private void button2_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Multiselect = true; fileDialog.Title = "请选择文件"; fileDialog.Filter = "所有文件(*.*)|*.*"; if (fileDialog.ShowDialog() == DialogResult.OK) { string[] names = fileDialog.FileNames; foreach(string file in names) { MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } private void button3_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; if (dialog.ShowDialog() == DialogResult.OK) { string foldPath = dialog.SelectedPath; DirectoryInfo theFolder = new DirectoryInfo(foldPath); FileInfo[] dirInfo = theFolder.GetFiles(); //遍历文件夹 foreach (FileInfo file in dirInfo) { MessageBox.Show(file.ToString()); } } }
相关文章推荐
- C# Stream 和 byte[] 之间的转换
- C#泛型学习(一)。
- (转)C#的 GC工作原理基础
- C#语言 数据类型 变量常量 数据转换 3.22
- C# 理解Thread.Sleep()
- C#解leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- C#中string和byte[]相互转换问题解决
- c#多维数组
- C#中委托和Lambda表达式
- 文件
- C#如何调用其他.config配置文件,就是2个乃至3个以上的config文件
- C#机房重构——导出excel表
- ffmpeg从rtsp抓流存flv[c# NReco.VideoConverter flv]
- c# 学习之一:编码约定
- 登山-C#-为枚举创建新方法
- c# - StringTest
- 如何使用C#创建WebService
- C# Winform中窗体的美化——用IrisSkin4.dll美化你的WinForm
- c#输入一个字符串,并把字符串的第一个字符变为大写,如果字符串中有空格则把空格的下个字符变为大写之后输出
- C# WinForm实现Win7 Aero磨砂效果