Server.MapPath to go two folder back from root

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.


Start with the root of your site with ~ and specify the full path: ~/Archive/Content.

You can't go back above site root because of security restrictions, see also this article from other solutions.

IIS purposefully prevents serving up content directly that is outside of the site path. However, you can create a virtual directory in IIS and have ISAPI Rewrite point to that. For example, create a virtual directory called /staticfiles that points to c:\test\data\static-files. As far as IIS is concerned, that's directly off of the root of the site in a folder called /staticfiles.


You can use Parent.Parent.FullName

  string grandParent  = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/")).Parent.Parent.FullName;

Tags:

C#

Asp.Net

Iis