【发布时间】:2010-10-15 15:52:46
【问题描述】:
我有这段代码,我得到一个 IOException 并且无法弄清楚问题是什么。 我正在尝试遍历目录中的子目录并列出所有 .JPG 文件。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["AllEmpsLoadPath"] = "\\\\intranet.org\\Photo Album\\Employees";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DirSearch((string)Session["AllEmpsLoadPath"]);
}
void DirSearch(string sDir)
{
foreach (string d in Directory.GetDirectories(sDir))
{
//I get an IOException here on the first iteration
//saying "There are no more files" and f is null
//even though there are subdirectories
foreach (string f in Directory.GetFiles(d, "*.JPG"))
{
BulletedList1.Items.Add(f);
}
DirSearch(d);
}
}
【问题讨论】: