2009-09-01 114 views
0

我需要检查一个文件夹是否存在于ASP.NET网站中。这是要在网站本身完成,我需要检查几个文件夹,所以要确保有小开销(即没有WebCLient调用等)检查网站文件夹是否存在的最佳方法是什么?

我的想法是,我可以做一个HttpServerUtility.MapPath(“ 〜/“)获取根路径,然后使用Directory.Exists(rootPath + webPath)来检查文件夹。假设文件夹结构是相同的,这对于服务器场会起作用吗?

这是最好的办法还是有一些equavalent哟WebDirectory.Exists(〜/ mysite的/ somepath)

所有评论欢迎。

回答

4

using System.IO;

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

+0

这印证了我的想法... – 2009-09-01 11:36:36

+0

使用Server.Mappath正是所需要的我,谢谢。 – lathomas64 2014-05-15 17:35:51

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