简体   繁体   English

选择文件夹中的html文件

[英]Select html files in a folder

Using "folderBrowserDialog1" can i select only HTML files in a folder. 我可以使用“ folderBrowserDialog1”仅选择文件夹中的HTML文件。

My code is like this : 我的代码是这样的:

private void btnBrowse_Click(object sender, EventArgs e)
{
   DialogResult result = folderBrowserDialog1.ShowDialog();
   if (result == DialogResult.OK)
    {
       string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
       MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
    }
 }

Use: DirectoryInfo.GetFiles Method (String) 使用: DirectoryInfo.GetFiles方法(字符串)

Returns a file list from the current directory matching the given search pattern. 从当前目录返回与给定搜索模式匹配的文件列表。

string[] files = Directory.GetFiles("*.html");

Or if you only want to html files to be available for selection you can use: 或者,如果您只希望html文件可供选择,则可以使用:

OpenFileDialog 打开文件对话框

folderBrowserDialog1.Filter = "*.html | *.htm";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开文件夹并选择多个文件 - Open Folder and Select multiple files 根据名称约定从文件夹中选择文件 - Select Files From Folder Depending on Name Convention 从文件夹中选择并打印PDF文件列表 - Select and Print list of PDF files from a folder 如何从C#中的选定文件夹中仅选择XML文件? - How to select only XML files from selected folder in C#? 如何通过对话框选择文件夹并处理它包含的所有文件 - How to select a folder through a dialog and process all the files it contains 如何按文件夹对文件(字符串)列表进行分组并对组执行 select 方法 - How to group list of files (strings) by folder and perform select method on the group 列出/下载Http文件夹文件而不解析HTML - List/download Http folder files without parsing HTML 如何将CSS参考链接添加到文件夹中的本地HTML文件? - How to add CSS reference link to local HTML files in folder? 如何确保用户选择特定文件夹并从所选文件夹中的文件中删除文件扩展名? - How to make sure user select specific folder and remove file extension from files in the selected folder? 使用 CommonOpenFileDialog 到 select 一个文件夹,但仍显示 Windows 10 文件夹中的文件 - Using a CommonOpenFileDialog to select a folder but still show files within the folder in Windows 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM