简体   繁体   English

检查网站文件夹是否存在的最佳方法是什么?

[英]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.

相关问题 检查数据库中是否已存在列表项的最佳方法是什么? - What is the best way to check if an item of a list already exists in database? 检查EntityFramework中是否存在相关实体的最佳方法是什么 - What is the best way to check if related entity exists in EntityFramework 检查 S3 object 是否存在的最佳方法是什么? - what's best way to check if a S3 object exists? 检查ArrayList上是否存在任何值的最佳方法 - Best way to check if any value exists on ArrayList 使用C#检查SQL Server表中是否存在记录的最佳方法是什么? - What is the best way to check if a record exists in a SQL Server table using C#? 确定NamedDataSlot是否存在的最佳方法是什么 - What's the best way to determine if NamedDataSlot exists 自动自我更新网站的最佳方法是什么? - What is the best way to automatically self update a website? 在自己内部移动文件夹的最佳方法是什么? - What is the best way to move a folder inside itself? 检查项目是否存在于SQL Server CE中的最佳方法? - Best way to check if an item exists in sql server ce? 在添加密钥之前检查字典中是否存在密钥的最佳方法? - Best way to check if a key exists in a Dictionary before adding it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM