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) + @"\所在项目名\Lic\DDTek.lic";// updir就是上一级物理路径了

posted @ 2017-04-18 07:24  914556495  阅读(2016)  评论(0编辑  收藏  举报