petko_stankoski petko_stankoski - 1 year ago 182
C# Question

Server.MapPath to go two folder back from root

Here is how I do it:


HI know that '.' is for the root of the project, but how to go a few folders back?

Rup Rup
Answer Source

If you really need the grandparent path, you can get it from the root path using Path.GetDirectoryName():

string root = Server.MapPath("~");
string parent = Path.GetDirectoryName(root);
string grandParent = Path.GetDirectoryName(parent);

But your web app very likely won't have permission to read or write there - I'm not sure what you're going to do with it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download