0

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.

vandu
  • 196
  • 1
  • 3
  • 17

1 Answers1

0

99% the error it's that you missed a "-" in MIME types. Correct one is:

application/octet-stream

so basically android it's not detecting right type.

MrPk
  • 2,862
  • 2
  • 20
  • 26
  • i changed the code but still the file is downloading in .htm extension – vandu Feb 25 '14 at 09:21
  • look here: http://stackoverflow.com/questions/4674737/avoiding-content-type-issues-when-downloading-a-file-via-browser-on-android (last reply) – MrPk Feb 25 '14 at 09:41
  • Thanks for ur rply i set the ContentType to application/octet-stream and the Content-Disposition filename value in double quotes and the Content-Disposition filename extension in UPPERCASE wat else i need to change in my code. im totally struck with this issue so pls help – vandu Feb 25 '14 at 09:53
  • I'm sorry but can't help directly for C# since I don't know it. You can give a try to set an explicit header Content Type (in addition or in alternative), so Response.AddHeader("Content-Type", "CONTENT=""application/octet-stream"");. Also, try to open htm that Android downloads, maybe you'll see something strange or string badly created! – MrPk Feb 25 '14 at 10:09
  • hi i got solution for the download problem. i attached handler to solve the issue – vandu Mar 03 '14 at 04:01