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

发布于 2024-08-03 17:45:06 字数 293 浏览 1 评论 0原文

我需要检查 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗心遗梦遗幸福 2024-08-10 17:45:06

使用 System.IO;
<代码>
if (Directory.Exists (Server.MapPath("~/Views/Common/")))
{
//东西
}

using System.IO;

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

怎樣才叫好 2024-08-10 17:45:06
bool folderExists = Directory.Exists(@"c:\windows");
bool folderExists = Directory.Exists(@"c:\windows");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文