I am developing a website where users will download the attachment file from the website. The download functionality works fine in all desktop browsers but the download fails in android browser. The file downloading in ".htm" extension. you can find the download script (c#) below:
protected void lnkButton_Click(object sender, EventArgs e) {
try {
LinkButton lnkButton = (LinkButton)sender;
System.IO.FileInfo currentFIleInfo = new System.IO.FileInfo(lnkButton.CommandArgument);
if(currentFIleInfo.Exists) {
Response.Clear();
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Cache-Control", "no-cache");
Response.AddHeader("Content-Disposition", "attachment; filename=""" + lnkButton.Text.ToUpper() + """" );
Response.AddHeader("Content-Length", currentFIleInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.TransferFile(currentFIleInfo.FullName);
Response.End();
}
} catch(Exception ex) {
MMHLogger.Error(ex);
}
}
My aspx page looks like this
<table border="0" cellpadding="0" cellspacing="3px">
<tr>
<td>
<a href='<%# Eval("FileName", "../SiteContent/Uploads/{0}") %>' target="_blank">
<asp:Image ID="Image1" ToolTip='<%# Eval("AlternativeText")%>' AlternateText='<%# Eval("AlternativeText")%>' ImageUrl='<%# Eval("FileName", "ImageThumbnailer.ashx?img=SiteContent/Uploads/{0}&size=72") %>' runat="server" BorderWidth="0" />
</a>
</td>
<td>
<%# Eval("ImageName")%>
<br />
<%# Eval("ImageSize")%>
</td>
<td>
<a href='<%# Eval("FileName", "../SiteContent/Uploads/{0}") %>' target="_blank">View</a>
</td>
</tr>
</table>
I tried all the suggestions which listed in this blog : http://www.digiblog.de/2011/04/android-and-the-download-file-headers/
But still the file download as in .htm extension in android browser.