Server.MapPath to go two folder back from root

后端 未结 5 1126
鱼传尺愫
鱼传尺愫 2020-12-30 12:12

Here is how I do it:

HttpContext.Current.Server.MapPath(@\"~\\~\\~\\Content\\\")

HI know that \'.\' is for the root of the project, but how

5条回答
  •  醉话见心
    2020-12-30 12:39

    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.

提交回复
热议问题