views:

195

answers:

2

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.

+3  A: 

using System.IO;

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

Christopher Kelly
That confirms my thoughts...
Mark Redman
A: 
bool folderExists = Directory.Exists(@"c:\windows");
Raghav Khunger