2

(My environment is iOS 8, IPhone 5S)

If you create a page using the tag

<meta name="apple-mobile-web-app-capable" content="yes" />

Then, using a download button (asp:Button) that adds a preview-able item such as PDF/Word Doc to the response - The web app will full screen preview the item, with no ability to go back to the web app.

 byte[] bytes = this.Data;
 HttpContext.Current.Response.Buffer = true;
 HttpContext.Current.Response.Charset = "";
 HttpContext.Current.Response.ContentType = this.MimeType;
 HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + this.FileName);
 HttpContext.Current.Response.BinaryWrite(bytes);
 HttpContext.Current.Response.Flush();

The user is then forced to hit the iPhone home button, and re-open the app. How may I make this force file download, or alternatively give any options at all to the user?

Edit - This works fine in android as long as android app was added to home screen via Chrome.

Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
DFTR
  • 861
  • 10
  • 30

2 Answers2

0

Using a postback to add the file to the response didn't work, as IOS would preview it. Using another ASPX page didn't work, as it would act the same way.

I used a generic ASHX handler, a client side target = _blank anchor to hit it and that works. Unfortunately this can't pass the session, because it works due to opening the safari full browser.

None of these files are private however, so that works for me. I'd prefer a solution that doesn't require swapping to the full browser, if anybody is able to come up with a solution that is better.

DFTR
  • 861
  • 10
  • 30
  • 1
    Rather than display the PDF standalone, why don't you [embed it in a webpage](http://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html)? – mason Apr 28 '15 at 18:20
0
  • Two changes we have made,
  • We wrote
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.Clear(); before setContentType.
  • We have used Applicaton/octet-stream instead Applicaton/pdf

                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Buffer = true;
    
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.AddHeader("Cache-control", "no-store");
                var userAgent = HttpContext.Current.Request.UserAgent.ToLower();
                if (userAgent.Contains("iphone;"))
                {
                    HttpContext.Current.Response.ClearHeaders();
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Claim_Report_" + strFileName + ".pdf"));
    
                }
                else if (userAgent.Contains("ipad;"))
                {
                    HttpContext.Current.Response.ClearHeaders();
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Claim_Report_" + strFileName + ".pdf"));
    
                }
                else
                {
                    HttpContext.Current.Response.ContentType = "application/pdf";
                    HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Claim_Report_" + strFileName + ".pdf"));
                }
    
                HttpContext.Current.Response.BinaryWrite(Buffer);
                //HttpContext.Current.Response.End();
                HttpContext.Current.Response.Flush();
                HttpContext.Current.ApplicationInstance.CompleteRequest();
    
Papun Sahoo
  • 407
  • 5
  • 13