求救:关于网站下载的问题
下载代码:1 <a href="下载文件地址">下载</a>
2
protected void download_Click(object sender, ImageClickEventArgs e)
{
//string Title = "Two.And.A.Half.Men.S06E04.rmvb";//"中文的名称.doc";//这里是欲显示在另存为里面的文件名字,必须有后缀名
string fileName = Server.MapPath(Request["filename"]);//"d:\test.doc";//这里是实际存在的文件路径
string Title = fileName.Substring(fileName.LastIndexOf('\\')+1);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Buffer = false;
Response.Clear();
Response.ContentType = "APPLICATION/OCTET-STREAM;charset=UTF-8";//dt.Rows[0]["BLB_MIMETYPE"].ToString();//"APPLICATION/OCTET-STREAM";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.UrlEncode(Title) + "\"");
try
{
//Response.AddHeader("Content-Length", file.Length.ToString());
Response.WriteFile(fileName);
Response.Flush();
Response.Clear();
Response.End();
}
catch (Exception ex)
{
Response.ContentType = "text/html; charset=gb2312";
Response.Write("<script>alert('下载文件错误:" + ex.Message + "');</script>");
}
}
问题:
当电脑安装下载软件(如迅雷):第一个代码是正常的,而第二个代码会出现下载该页面(即.aspx页面)
当电脑卸载下载软件:第一个代码出现该页面无法显示,而第二个代码正常
不知道有没有较好的解决方案
求救~~~~~~~~~~~~~~~