Reputation: 409
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
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