C#编程-122:文件夹选择之FolderBrowserDialog控件
【摘要】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using ...
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace FolderBrowserDialogTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnTxt_Click(object sender, EventArgs e)
- {
- folderBrowserDialog1.Description = "请选择一个包含txt的文件夹";
- folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
- folderBrowserDialog1.ShowNewFolderButton = false;
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- string folderPath = folderBrowserDialog1.SelectedPath;
- string[] files = Directory.GetFiles(folderPath);
- foreach (string str in files)
- {
- if (str.Substring(str.LastIndexOf('.') + 1).ToLower() == "txt")
- {
- richTextBox1.AppendText(str + "\n");
- }
- }
- }
- }
- private void btnDoc_Click(object sender, EventArgs e)
- {
- folderBrowserDialog1.Description = "请选择一个包含doc的文件夹";
- folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
- folderBrowserDialog1.ShowNewFolderButton = true;
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- string folderPath = folderBrowserDialog1.SelectedPath;
- string[] files = Directory.GetFiles(folderPath);
- foreach (string str in files)
- {
- if (str.Substring(str.LastIndexOf('.') + 1).ToLower() == "doc")
- {
- richTextBox1.AppendText(str + "\n");
- }
- }
- }
- }
- }
- }
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/81049259
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)