简体   繁体   中英

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

I need to check if a folder exists within an ASP.NET website. This is to be done within the website itself and I need to check a few folders so want to make sure there is little overhead (ie no WebCLient calls etc)

My thinking is that I could do a HttpServerUtility.MapPath("~/") to get the root path and then a Directory.Exists(rootPath + webPath) to check the folders. Would this work for Server Farms assuming the folder structures are the same?

Is this the best way or is there some equavalent yo WebDirectory.Exists(~/mysite/somepath)

All comments welcome.

使用System.IO;

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM