我使用Asp.net
和C#
来运行此网站并接近移动版,我使用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";
}
}
答案 0 :(得分:0)
我有类似的问题,Chrome中的文件下载失败了。我刚刚删除了Response.Flush()和Response.Close(),只添加了有效的Response.End()