Force browser to download PDF document instead of opening it

You should look at the “Content-Disposition” header; for example setting “Content-Disposition” to “attachment; filename=foo.pdf” will prompt the user (typically) with a “Save as: foo.pdf” dialog, rather than opening it. This, however, needs to come from the request that is doing the download, so you can’t do this during a redirect. However, ASP.NET offers Response.TransmitFile for this purpose. For example (assuming you aren’t using MVC, which has other preferred options):

Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf");
Response.TransmitFile(filePath);
Response.End(); 

Leave a Comment