检查网站文件夹是否存在的最佳方法是什么?
我需要检查 ASP.NET 网站中是否存在文件夹。这是要在网站本身内完成的,我需要检查一些文件夹,所以想确保很少的开销(即没有 WebCLient 调用等)
我的想法是我可以做一个 HttpServerUtility.MapPath("~/")获取根路径,然后使用 Directory.Exists(rootPath + webPath) 来检查文件夹。假设文件夹结构相同,这对于服务器场是否有效?
这是最好的方法还是有一些等效的 WebDirectory.Exists(~/mysite/somepath)
欢迎所有评论。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 System.IO;
<代码>
if (Directory.Exists (Server.MapPath("~/Views/Common/")))
{
//东西
}
using System.IO;
if (Directory.Exists (Server.MapPath("~/Views/Common/")))
{
//Stuff
}