MVC获取文件路径

string ss = base.HttpContext.Request.RawUrl;//获取当前项目路径
string cc= Server.MapPath("DDTek.lic");//获取绝对路径,参数文件名称

//HttpContext.Server请求对象非静态

//HttpContext httpcontext = System.Web.HttpContext.Current;

HttpContext httpcontext = HttpContext.Current;
string LicensePath = httpcontext.Server.MapPath("DDTek.lic");//获取绝对路径,参数文件名称

获取项目的上一级目录

string cc = HttpRuntime.AppDomainAppPath.ToString();//获取承载在当前应用程序域中的应用程序的应用程序目录的物理驱动器路径。用于App_Data中获取
int idx = cc.TrimEnd('\').LastIndexOf('\');
string LicensePath = cc.Substring(0, idx) + @"所在项目名LicDDTek.lic";// updir就是上一级物理路径了

原文地址:https://www.cnblogs.com/914556495wxkj/p/6725928.html