我有解决方案“解决方案”和两个项目:
在web api项目中,我访问这样的文件:
public HttpResponseMessage GetPdfPage()
{
HttpResponseMessage responce = new HttpResponseMessage();
responce.Content = new StreamContent(new FileStream(HttpContext.Current.Server.MapPath("~/somefile.pdf"), FileMode.Open, FileAccess.Read));
responce.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return responce;
}
如何修改文件路径?
答案 0 :(得分:1)
我认为共享文件夹是更好的解决方案 http://support.microsoft.com/kb/324267
答案 1 :(得分:0)
我还遇到了类似的问题,我需要在同一解决方案下从BLL项目访问另一个项目(主要)的Upload文件夹。 为此,我使用绝对路径(非硬编码)为Upload文件夹。我认为下面的代码也适合你。
public HttpResponseMessage GetPdfPage()
{
HttpResponseMessage responce = new HttpResponseMessage();
string basePath = System.AppDomain.CurrentDomain.BaseDirectory;
responce.Content = new StreamContent(new FileStream(HttpContext.Current.Server.MapPath(basePath +"somefile.pdf"), FileMode.Open, FileAccess.Read));
responce.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return responce;
}