Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Created December 10, 2013 09:14
Show Gist options
  • Save fliiiix/7887821 to your computer and use it in GitHub Desktop.
Save fliiiix/7887821 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.IO;
public class PdfHandler: IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
string fileToServe = context.Request.Path;
FileInfo pdf = new FileInfo(context.Server.MapPath(fileToServe));
context.Response.ClearContent();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + pdf.Name);
context.Response.AddHeader("Content-Length", pdf.Length.ToString());
context.Response.TransmitFile(pdf.FullName);
context.Response.Flush();
context.Response.End();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment