簡體   English   中英

檢查網站文件夾是否存在的最佳方法是什么?

[英]What is the best way to check if a website folder exists?

我需要檢查ASP.NET網站中是否存在文件夾。 這是在網站本身內部完成的,我需要檢查一些文件夾,以便確保幾乎沒有開銷(例如,沒有WebCLient調用等)

我的想法是我可以執行HttpServerUtility.MapPath(“〜/”)來獲取根路徑,然后執行Directory.Exists(rootPath + webPath)來檢查文件夾。 假設文件夾結構相同,這對服務器場是否有效?

這是最好的方法還是WebDirectory.Exists(〜/ mysite / somepath)

歡迎所有評論。

使用System.IO;

if (Directory.Exists (Server.MapPath("~/Views/Common/")))
{
//Stuff
}

bool folderExists = Directory.Exists(@"c:\windows");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM