I'm having an issue downloading a PDF file from my custom asp.net site in the out of the box browser on an Android tablet (a Motorola Xoom).
I'm using Response.OutputStream.Write to send the file because it's having to read the file from a UNC path. This method works on IE, Firefox, Safari, and on iPad, but doesn't work on the browser on the Xoom. However, when I downloaded Firefox on the Xoom I was able to download the file just fine.
I've found a couple of spots suggesting I use the following headers: Content-Type: application/octet-stream Content-Disposition: attachment; filename="MyFileName.PDF"
I've tried this with no luck. I also tried using Content-Types of application/pdf and application/force-download and every combination of filename capitalized, extension capitalized, extension lowercase, double quotes, single quotes, no quotes, etc... for Content-Disposition and have yet to find anything that works.
I have also found that if I execute the code to download the file on Page_Load it is able to download, but if I do a postback and then execute the code (clicking on a link button to download the file) it doesn't work
Has anyone been able to download a file using custom C# code on the OOTB Android 3.0 browser?
This is old but in case anyone comes across this issue:
Check unknown sources under settings --> applications.
Make sure you have PDF defined in MIME Types (application/pdf) on the IIS server.
Also if you are using a file handler you will need to set the header info.
This code block is an example of what would be used in a 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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With