使用OpenFileDialog组件打开多个文
2024-08-29 13:43:23
实现效果:
知识运用:
OpenFileDialog组件的Multiselect属性 //是否允许多选
public bool Multiselect {get;ser;}
FileNames属性 //获取所有选定的文件的文件名
public string[] FileName {get;}
实现代码:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "txt文件(*.txt)|*.txt";
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string Content = string.Empty;
foreach(string s in openFileDialog1.FileNames) //注意是s
{
StreamReader sr = new StreamReader(s,Encoding.Default);
Content += sr.ReadToEnd();
sr.Close();
}
textBox1.Text = Content;
}
}
最新文章
- Startup配置类 居然又是约定
- 设置apache https服务
- ReactiveCocoa信号使用方法
- [Java] Java中List 去掉重复的值,并保持原先List顺序
- Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
- 【Android 界面效果24】Intent和PendingIntent的区别
- Java-20个非常有用的程序片段
- QT国际化
- 《Getting Started with WebRTC》第一章 WebRTC介绍
- CentOS上安装WordPress搭建博客平台
- VS2017 连接Linux
- 2018牛客网暑期ACM多校训练营(第一场)J Different Integers(树状数组)
- VMware5.5-VMware补丁程序VUM
- log4net写入日志到sqlserver数据库
- 转 安装Nginx 1.2.0+PHP 5.4.3(FastCGI)+MySQL 5.5.24
- ajax post方式下载后台传来的文件
- no matching function for call to ‘std::basic_string<;char>;::assign(std::string&;, int)
- 自增ID时如何插入ID
- 一行代码彻底禁用WordPress缩略图自动裁剪功能
- 使用python创建生成动态链接库dll