/ Published in: ASP

"This was a requirement that the client had because there were differences in how various browsers were displaying the same PDFs. By setting the "Content-Disposition" header to "attachment" it forces the user to download the file. I thought this was kind of cool, so I thought I'd share it. This is how I implemented it for Kentico's GetFile handler."
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <summary> /// Sends the given file within response /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputFile file) { // Clear response. Response.Cookies.Clear(); Response.Clear(); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); if ((file != null) && file.IsValid) { if (file.MimType == "application/pdf") { // file is a PDF -- force it to download ("save as") Response.AddHeader("Content-Disposition", "attachment; filename" + file.Attachment.AttachmentName); }
Comments
