Created
December 10, 2013 09:14
-
-
Save fliiiix/7887821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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