java 模态窗口下载文件_asp.net模态窗口下载文件解决方案

思路,在模态窗口页面放一个影藏的iframe。

首先,我们新建一个模态窗口,在模态窗口a.aspx

Java代码 icon_copy.gif

html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

点击这里下载文件

点击这里下载文件

后台代码:

Java代码 icon_copy.gif

protectedvoidibDownLoad_Click(object sender, EventArgs e)

{

string filePath = Server.MapPath("\\PDF\\a.txt");

download.Attributes["src"] ="DownLoad.aspx?filePath="+ filePath;

}

protected void ibDownLoad_Click(object sender, EventArgs e) { string filePath = Server.MapPath("\\PDF\\a.txt"); download.Attributes["src"] = "DownLoad.aspx?filePath=" + filePath; }

处理文件下载页面DownLoad.aspx,页面代码不写,在后台代码写:

Java代码 icon_copy.gif

protectedvoidPage_Load(object sender, EventArgs e)

{

string filePath = Request.QueryString["filePath"];

//string filePath = Server.MapPath("\\PDF\\a.txt");

if(File.Exists(filePath))

{

FileInfo file =newFileInfo(filePath);

Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");//解决中文乱码

Response.AddHeader("Content-Disposition","attachment; filename="+ Server.UrlEncode(file.Name));//解决中文文件名乱码

// Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

Response.AddHeader("Content-length", file.Length.ToString());

Response.ContentType ="appliction/octet-stream";

Response.WriteFile(file.FullName);

Response.End();

}

}

protected void Page_Load(object sender, EventArgs e) { string filePath = Request.QueryString["filePath"]; //string filePath = Server.MapPath("\\PDF\\a.txt"); if (File.Exists(filePath)) { FileInfo file = new FileInfo(filePath); Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); //解决中文文件名乱码 // Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-length", file.Length.ToString()); Response.ContentType = "appliction/octet-stream"; Response.WriteFile(file.FullName); Response.End(); } }

OK,完成,这样可以解决模态窗口点击下载链接没反应,或者弹出提示等等一些问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值