Я использую функцию HttpContext.Current.Server.MapPath
, чтобы найти файл StudentReport.rdlc
, который находится под Class Library Project
.
Структура решения:
![enter image description here](https://i.stack.imgur.com/mF5Rf.png)
Я вызываю функцию ниже, которая находится в Class Library Project
из Web API Project
с именем WebDemo
.
public class Reports
{
public string GetReportPath()
{
string path1 = System.AppDomain.CurrentDomain.BaseDirectory;
var path2 = System.Web.HttpContext.Current.Server.MapPath("~/StudentReport.rdlc");
var path3 = System.Web.HttpContext.Current.Server.MapPath("~/BL/ClassLib/StudentLib
/Reports/StudentReport.rdlc");
var path4 = System.Web.HttpContext.Current.Server.MapPath("~/StudentLib/Reports
/StudentReport.rdlc");
string path5 = System.Web.Hosting.HostingEnvironment.MapPath("~/StudentLib/Reports
/StudentReport.rdlc");
return path5;
}
}
Как вы можете видеть, я пыталсявсе комбинации Server.MapPath
, но все равно он добавляет каталог WebDemo
во все пути.
Текущий путь:
"C:\\Users\\tom\\source\\repos\\WebDemo\\WebDemo\\StudentLib\\Reports\\StudentReport.rdlc"
Ожидаемый путь:
"C:\\Users\\tom\\source\\repos\\WebDemo\\StudentLib\\Reports\\StudentReport.rdlc"
Могу ли я знать, почему это происходит?
Любая помощь будет отличной.