Anton Putov
Anton Putov

Reputation: 1981

Access files from another project same solution asp.net mvc

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

Answers (2)

Uday
Uday

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

Joan Caron
Joan Caron

Reputation: 1970

I think Shared folder is a better solution http://support.microsoft.com/kb/324267

Upvotes: 1

Related Questions