Download files in Android 3.0 browser from my ASP.NET site

I had a problem downloading a PDF file from my user site asp.net in a browser from a browser on an Android tablet (Motorola Xoom).

I use Response.OutputStream.Write to send the file because it must read the file from the UNC path. This method works on IE, Firefox, Safari, and iPad, but does not work on the Xoom browser. However, when I downloaded Firefox to Xoom, I was able to download the file just fine.

I found a couple of spots suggesting using the following headers: Content-Type: application / octet-stream Content-Disposition: attachment; file name = "MyFileName.PDF"

I tried this with no luck. I also tried using Content-Types of application / pdf and application / force-download and each combination of a file name with an uppercase letter, an uppercase extension, a lowercase extension, double quotes, single quotes, without quotes, etc. For Content-Disposition and still find something that works.

I also found that if I execute the code to download the file on the_Load page, it can load, but if I do the postback and then execute the code (by clicking the link button to download the file), it doesn’t work

Has anyone been able to upload a file using custom C # code in OOTB Android 3.0 browser?

+6
source share
2 answers

This is old, but in case anyone comes across this problem:

Check unknown sources in settings β†’ applications.

Ensure that the PDF file is defined in MIME types (application / pdf) on the IIS server.

Also, if you use a file handler, you will need to set the header information.

This block code is an example of what will be used in the file handler:

string dirpath = System.Configuration.ConfigurationManager.AppSettings["FilePath"]; string file = System.Configuration.ConfigurationManager.AppSettings["FileName"]; System.IO.FileInfo fi = new System.IO.FileInfo(dirpath + file); string contentlen = fi.Length.ToString(); context.Response.Buffer = true; context.Response.Clear(); context.Response.AddHeader("content-disposition", "attachment; filename=" + file); context.Response.AddHeader("content-length", contentlen); context.Response.ContentType = "application/pdf"; try { context.Response.WriteFile(dirpath + file); } catch (Exception) { context.Response.Redirect("Error.aspx"); } 
+1
source

I have no idea why this happens, but if you can load the file inside the Page_Load block, the workaround will be with the highlighted page to load, where you call the load function inside Page_Load .

To make it more compatible with the rest of your site (if necessary), you can transfer various parameters to the page to download different files or redirect to this page only if you find that the site is running in the Android browser.

I will add code examples soon.

0
source

Source: https://habr.com/ru/post/887386/


All Articles