-3
这里我有一个问题,就是如何列出列表框中的搜索文件夹的内容(文件)。问题是我有很多文件夹,每个文件夹都有很多格式为.txt的文件。我需要,如果我在文本框中键入文件夹名称并单击按钮,在列表框中显示搜索文件夹内的所有文件。在下面我添加我的代码,但它不起作用。请帮我....如何在列表框中列出搜索文件夹的内容(文件)
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
string search = TextBox1.Text; // here type the folder name
if (search != "")
//DirectoryInfo d = new DirectoryInfo(@"\\192.123.1.18\Report\Result" + search);
{
string[] files = Directory.GetFiles(@"\\192.123.1.16\Report\Result\"+ search + "*" + "*.*");
foreach (string file in files)
{
//ListBox1.Items.Add(new ListItem(Path.GetFileName(file), file));
ListBox1.Items.Add(new ListItem(Path.GetFileName(file), file)); // listed all files in the search folder
}
{
search = "";
}
}
else
{
Response.Write("<script>alert('Please Enter Search Keyword');</script>");
}
}
非常感谢你的朋友......这是工作...我有另外一个问题,如何将文件列表插入到列表框中根据修改日期....请帮助我,因为每个文件夹有很多文件.... –
@ T.Kumar你注意到 - 这是另一个问题,所以根据SO的规则,你应该问新问题 – Backs
好朋友...顺便说一句,感谢代码...这真的很有帮助......;) –