文件下载不可逾越的问题:无法调用IE

terencegan 2006-10-31 09:23:44
请教各位老大:
我做文件下载,弹出"文件下载对话框",可以保存文件;但是当打开文件时,IE不是弹出一个新IE,而是利用桌面上已经打开的IE,甚至可以会促使页面关闭,请高人指点,解决问题,马上给分!

hyperlink.aspx文件,有hyperlinke控件
有如下代码:
protected void Page_Load(object sender, EventArgs e)
{

if (!this.IsPostBack)
{

this.HyperLink1.NavigateUrl = "download.aspx";
this.HyperLink1.Target = "_blank";
this.HyperLink1.Text = "测试文件打开";
this.HyperLink1.Target = "_blank";
}
}
download.aspx.cs文件,有如下代码:
protected void Page_Load(object sender, EventArgs e)
{

if (!this.IsPostBack)
{
try
{

string path = Server.MapPath("linshilanmu3.jpg");
if (!System.IO.File.Exists(path))
{

this.Page.Response.End();
}

System.IO.FileInfo file = new System.IO.FileInfo(path);

this.Page.Response.Clear();
this.Page.Response.Buffer = false;
this.Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);
this.Page.Response.AddHeader("Content-Length", file.Length.ToString());
#region//文件下载类型
string filename = "linshilanmu3.jpg";
string strFilePostfix = filename.Substring(filename.Length - 4, 4).ToLower();
if (strFilePostfix == ".asf")
this.Response.ContentType = "video/x-ms-asf";
else if (strFilePostfix == ".avi")
this.Response.ContentType = "video/avi";
else if (strFilePostfix == ".doc")
this.Response.ContentType = "application/msword";
else if (strFilePostfix == ".zip")
this.Response.ContentType = "application/zip";
else if (strFilePostfix == ".xls")
this.Response.ContentType = "application/vnd.ms-excel";
else if (strFilePostfix == ".avi")
this.Response.ContentType = "video/avi";
else if (strFilePostfix == ".gif")
this.Response.ContentType = "image/gif";
else if (strFilePostfix == ".jpg" || strFilePostfix == ".jpeg")
this.Response.ContentType = "image/jpeg";
else if (strFilePostfix == "audio/wav")
this.Response.ContentType = "audio/wav";
else if (strFilePostfix == ".mpg" || strFilePostfix == ".mpeg")
this.Response.ContentType = "video/mpeg";
else if (strFilePostfix == ".rtf")
this.Response.ContentType = "application/rtf";
else if (strFilePostfix == ".htm" || strFilePostfix == ".html")
this.Response.ContentType = "text/html";
else if (strFilePostfix == ".txt")
this.Response.ContentType = "text/plain";
else
this.Response.ContentType = "application/octet-stream";
#endregion
this.Page.Response.WriteFile(file.FullName);
this.Response.Flush();

this.Page.Response.End();
}
catch
{

this.Page.Response.Write("附件不存在或者已经被删除!");
}

}
}
...全文
262 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsyhello 2006-12-26
  • 打赏
  • 举报
回复
已经定义this.HyperLink1.Target = "_blank";应该没有问题啊,有的浏览器倒是保存或取消后出现空白页面,不知搂主如何解决的?
webdiyer 2006-11-01
  • 打赏
  • 举报
回复
下载页面也做过不少,不过没见过这种问题,如果实在不行,你可以单独再做个跳转的页面,下载时先在新窗口中打开这个页面,在这个页面中再跳转到download.aspx页面实现下载
terencegan 2006-10-31
  • 打赏
  • 举报
回复

protected void LinkButton1_Click(object sender, EventArgs e)
{
this.Response.Write("<script>window.open('download.aspx')</script>");
}

也不能解决啊
真相重于对错 2006-10-31
  • 打赏
  • 举报
回复
那句你写在哪呢??
你应该用linkbutton代替this.HyperLink1
然后再linkbutton的click事件里写
yangye1211 2006-10-31
  • 打赏
  • 举报
回复
IE7修正了这个 bug
terencegan 2006-10-31
  • 打赏
  • 举报
回复
try
Response.Write("<script>window.open(\"download.aspx\")</script>")
,这个方法还是无法解决,不过谢谢您的关注
真相重于对错 2006-10-31
  • 打赏
  • 举报
回复
try
Response.Write("<script>window.open(\"download.aspx\")</script>")

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧