I have solution "solution" and two projects:
In web api project I access files like this:
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;
}
How must I modify path to file?
我认为共享文件夹是一个更好的解决方案http://support.microsoft.com/kb/324267
I also faced a similar kind of problem where I need to access the Upload folder of another project(main) from the BLL project under same solution. For that I have used absolute path(not hardcoded) for the Upload folder. I think the code below should also work for you.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.