[英]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. 我需要检查ASP.NET网站中是否存在文件夹。 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)
这是在网站本身内部完成的,我需要检查一些文件夹,以便确保几乎没有开销(例如,没有WebCLient调用等)
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. 我的想法是我可以执行HttpServerUtility.MapPath(“〜/”)来获取根路径,然后执行Directory.Exists(rootPath + webPath)来检查文件夹。 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) 这是最好的方法还是WebDirectory.Exists(〜/ mysite / somepath)
All comments welcome. 欢迎所有评论。
使用System.IO;
if (Directory.Exists (Server.MapPath("~/Views/Common/")))
{
//Stuff
}
bool folderExists = Directory.Exists(@"c:\windows");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.