首先添加引用:
using System.IO;
然后在Page_Load中编写代码:
string FilePath = "c:\\test";
if(!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
if(!Directory.Exists(FilePath + "\Abnormal"))
{
Directory.CreateDirectory(FilePath + "\Abnormal");
}
DirectoryInfo UnPostil = new DirectoryInfo(FilePath + "\Abnormal");
FileInfo[] ArrUnPostil = UnPostil.GetFiles();
LB_Postil.Items.Clear();
foreach (FileInfo FileName in ArrUnPostil)
{
if(FileName.Length > 0)
{
LB_Postil.Items.Add(FileName.Name);
}
}
代码中的LB_Postil是一个LISTBOX服务器控件。