Donwloading attachment on the native Android browser via CMS.UIControls.UniGridConfig.Action

Jaroslav Šebok asked on December 6, 2016 14:35

I have a problem explained here: http://stackoverflow.com/questions/4674737/avoiding-content-type-issues-when-downloading-a-file-via-browser-on-android

I want to download an attachment when CMS.UIControls.UniGridConfig.Action is clicked. This control uses _doPostBack which makes POST requests but some native Android browsers only download attachments via GET method.

I made a workaround which sets a session variable in unigrid_OnAction, reloads the page and builds a response (as GET) with file in Page_Load.

Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Accept-Header", aDocument.Length.ToString());
Response.AddHeader("Content-disposition", "attachment; filename=\"Dokument.PDF\"");
Response.AddHeader("Content-Length", aDocument.Length.ToString());
Response.BinaryWrite(aDocument);                    
Response.End();

Works like a charm in all desktop browsers, on iPhone browser also on Android Google Chrome but on the NATIVE ANDROID BROWSER IT DOESN'T. It writes the whole page's HTML source code (without the actual PDF data) into the PDF file and downloads it.

Spend 10 hours on google, nothing helped. Any ways to resolve this?

Recent Answers


Rohit Kumar answered on October 31, 2017 01:29

To make it work on native android browser you will need to set the ContentType to application/octet-stream and put Content-Disposition filename value in double quotes and write the Content-Disposition filename extension in uppercase.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.