Mark Redman
Mark Redman

Reputation: 24515

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. 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.

Upvotes: 0

Views: 2587

Answers (2)

Raghav
Raghav

Reputation: 9630

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

Upvotes: 0

KellCOMnet
KellCOMnet

Reputation: 1859

using System.IO;

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

Upvotes: 4

Related Questions