Get current directory in asp.net mvc

前端 未结 3 1760
别跟我提以往
别跟我提以往 2021-01-01 12:35

I am trying to construct a file path in order to read an XSLT file, like so:

string path = \"../_xslt/example.xslt\";
StreamReader reader = new StreamReader(         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 13:35

    You can use the HttpServerUtility.MapPath method to map any relative paths for you, in your controller this is easily accessible via the ControllerContext:

    string path = ControllerContext.HttpContext.Server.MapPath("~/_xslt/example.xslt");
    ...
    

提交回复
热议问题