Thursday, October 07, 2010

How to serve pdf file located outside the virtual folder

We can use a Generic Hanlder for this:
Markup:
<a href="GenericHandler.ashx?f=Application" title="Application">View Application</a>
Generic Handler:
public class GenericHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string f = context.Request.QueryString.Get("f");
        ///
        /// Option 1: from server location.
        ///
        f = @"\\servername\documents\" + f + ".pdf";
        ///
        /// Option 2: from disk location
        ///
        f = @"c:\data\documents\" + f + ".pdf";
        context.Response.Clear();
        context.Response.ContentType = "Application/pdf";
        context.Response.WriteFile(f);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...