Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > GetAtachment, force download View modes: 
User avatar
Member
Member
bartek.suchan-u2i - 1/11/2010 5:03:52 AM
   
GetAtachment, force download
Hi,
I am using get attachment function to download PDF file. Most of the browsers opens pdf instead of downloading it. Downloading file can be forced when we change response header. But how can I do that for response from getAttachment ?
And secont thing: can it affect only one type of browsers (ex. FF) ?

Thanks,
Bartek Suchan

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 1/12/2010 6:44:56 AM
   
RE:GetAtachment, force download
Hi,

You can change the Kentico CMS default behavior in ~\CMSPages\GetFile.aspx.cs file which is responsible for sending the file data to browser.

You may need to modify SendFile(CMSOutputFile file) method like this:

1) please find line about 360:

SetDisposition(file.Attachment.AttachmentName,file.Attachment.AttachmentExtension);

and comment it out.

2) now you need to add some information to header. Please add following line:

Response.AddHeader("Content-Disposition", "inline; filename=<your file name>");

Please note: Some browsers have their own settings how to handle certain documents so in that case this solution doesn't need to work properly.

Best regards,
Miroslav Remias.

User avatar
Member
Member
Piernik - 1/27/2010 5:44:10 AM
   
RE:GetAtachment, GetFile force download
Hi.

To force download of all pdf files you have to go to line about 289 in ~/cmspages/getfile.aspx.cs, and find something like:

// Setup the mime type - Fix the special types
string mimetype = file.MimeType;
switch (file.Attachment.AttachmentExtension.ToLower())
{
case ".flv":
mimetype = "video/x-flv";
break;

next, you have to add:

case ".pdf":
Response.AddHeader("Content-Disposition", "attachment");
break;

And that's it :)

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 2/1/2010 10:13:05 AM
   
RE:GetAtachment, GetFile force download
Hi,

thank you for your addition.

Regards,
Zdenek C.