选择文件夹中的html文件

时间:2013-03-07 09:11:29

标签: c#

使用“folderBrowserDialog1”我只能选择文件夹中的HTML文件。

我的代码是这样的:

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");
    }
 }

1 个答案:

答案 0 :(得分:5)

使用:DirectoryInfo.GetFiles Method (String)

  

从与给定匹配的当前目录返回文件列表   搜索模式。

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

或者,如果您只想选择html个文件,可以使用:

OpenFileDialog

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