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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...