asp.net為我們提供了檔案系統對象了,對于目錄與檔案判斷是否存在我們有System.IO.File.Exists與System.IO.Directory.Exists即可,下面看兩個應用執行個體。
判斷檔案是否存在
代碼如下
複制代碼
using System.IO; // 還需要命名空間,别忘了
if (System.IO.File.Exists("c:aaa.txt")) // 注意雙引号路徑應為雙斜杠
{
//########## 有aaa.txt檔案!
}
判斷目錄是否存在
if (System.IO.Directory.Exists("c:www.111cn.net")) // 注意雙引号路徑應為雙斜杠
//########## 有aaa檔案夾!