Reputation: 1981
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?
Upvotes: 1
Views: 2470
Reputation: 365
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;
}
Upvotes: 0
Reputation: 1970
I think Shared folder is a better solution http://support.microsoft.com/kb/324267
Upvotes: 1