user1958628
user1958628

Reputation: 409

Check if directory exists with dynamic path

How can I check if the directory exists with a dynamic path (~) not a fixed path (C:)?

My code:

Soin_Id = Request.QueryString["SoinId"];
string path = @"~\Ordo\Soin_"+Soin_Id+@"\";
if (Directory.Exists(path))
{
    ASPxFileManager_Ordo.Settings.RootFolder = path;
}
else
{
    ASPxFileManager_Ordo.Settings.RootFolder =  @"~\Ordo\";
}

With this condition, it's never true, even though the directory exists.

Upvotes: 1

Views: 876

Answers (1)

Habib
Habib

Reputation: 223392

You need to use Server.MapPath to resolve dynamic path to physical path on server.

if (Directory.Exists(Server.MapPath(path)))

also consider using Path.Combine for concatenation of path.

Upvotes: 4

Related Questions