1

我使用Asp.netC#运行这个网站并接近移动版本,我使用jQuery移动。当我通过桌面浏览器下载时工作正常,当我尝试通过手机下载时,出现错误

下载失败

我该如何解决?

这是我的代码

protected void lbAttach_Click(object sender, EventArgs e)
{
    if (this.IsPostBack)
    {                
        string sRFP = lblRFPNo.Text.ToString().Trim();
        if (dsRFP(sRFP).Tables[0].Rows[0]["Attachment"].ToString() != "")
        {
            byte[] Attach = (byte[])dsRFP(sRFP).Tables[0].Rows[0]["Attachment"];
            string strfn = Convert.ToString(dsRFP(sRFP).Tables[0].Rows[0]["AttachName"]);
            string ext = Path.GetExtension(strfn);

            Response.Buffer = true;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strfn.ToUpper() + "\"" );

            //BinaryWriter bw = new BinaryWriter(Response.OutputStream);
            //bw.Write(Attach);
            //bw.Close();
            Response.ContentType = ReturnExtension(ext);

            try
            {
                Response.BinaryWrite(Attach);
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }

            Response.End();
            Response.Flush();
            Response.Close();
        }
    }
}

private string ReturnExtension(string fileExtension)
{
    switch (fileExtension)
    {
        case ".htm":
        case ".html":
        case ".log":
            return "text/HTML";
        case ".txt":
            return "text/plain";
        case ".doc":
            return "application/ms-word";
        case ".tiff":
        case ".tif":
            return "image/tiff";
        case ".asf":
            return "video/x-ms-asf";
        case ".avi":
            return "video/avi";
        case ".zip":
            return "application/zip";
        case ".xls":
        case ".csv":
            return "application/vnd.ms-excel";
        case ".gif":
            return "image/gif";
        case ".jpg":
        case "jpeg":
            return "image/jpeg";
        case ".bmp":
            return "image/bmp";
        case ".wav":
            return "audio/wav";
        case ".mp3":
            return "audio/mpeg3";
        case ".mpg":
        case "mpeg":
            return "video/mpeg";
        case ".rtf":
            return "application/rtf";
        case ".asp":
            return "text/asp";
        case ".pdf":
            return "application/pdf";
        case ".fdf":
            return "application/vnd.fdf";
        case ".ppt":
            return "application/mspowerpoint";
        case ".dwg":
            return "image/vnd.dwg";
        case ".msg":
            return "application/msoutlook";
        case ".xml":
        case ".sdxl":
            return "application/xml";
        case ".xdp":
            return "application/vnd.adobe.xdp+xml";
        default:
            return "application/octet-stream";
    }
}
4

1 回答 1

0

我有类似的问题,文件下载在 Chrome 中失败。我刚刚删除了 Response.Flush() 和 Response.Close() 并添加了 Response.End() 有效

于 2016-09-23T11:32:40.713 回答