Return to Snippet

Revision: 47429
at June 8, 2011 02:08 by inreflection7


Initial Code
/// <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);
        }

Initial URL


Initial Description
"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."

Initial Title
Kentico - Force download of PDF

Initial Tags
download

Initial Language
ASP