用Response.Write("")导出word时网页自动关闭
时间:2011-12-16
来源:互联网
我用Response.Write("")来导出word,方法是当前页面用post提交给一个页面page2,在page2的Page_Load事件里输出,直接用在ie7、8、9都没问题。但当把这个页面嵌入到框架后,在IE7和IE9中正常,可以正常导出word;
但在IE8中就不行,弹出页面page2后马上自动关闭,也没有提示打开和下载,直接关了,如果这时候在浏览器中在输入page2的地址就可以下载,不知道IE8为什么会自动关闭。page2的导出代码如下:
protected void Page_Load(object sender, EventArgs e)
{
int upFileLength = Request.ContentLength;
byte[] FileArray = new Byte[upFileLength];
string name = "test";
System.IO.Stream fileStream = Request.InputStream;
fileStream.Read(FileArray, 0, upFileLength);
string test = System.Text.Encoding.UTF8.GetString(FileArray);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name).Replace("+", " ") + ".doc");
Response.Write(test);
Response.Flush();
Response.End();
}
但在IE8中就不行,弹出页面page2后马上自动关闭,也没有提示打开和下载,直接关了,如果这时候在浏览器中在输入page2的地址就可以下载,不知道IE8为什么会自动关闭。page2的导出代码如下:
protected void Page_Load(object sender, EventArgs e)
{
int upFileLength = Request.ContentLength;
byte[] FileArray = new Byte[upFileLength];
string name = "test";
System.IO.Stream fileStream = Request.InputStream;
fileStream.Read(FileArray, 0, upFileLength);
string test = System.Text.Encoding.UTF8.GetString(FileArray);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name).Replace("+", " ") + ".doc");
Response.Write(test);
Response.Flush();
Response.End();
}
作者: austo 发布时间: 2011-12-16
Response.Write("<script>window.close();</script>");
作者: FENG03 发布时间: 2011-12-16
引用 1 楼 feng03 的回复:
Response.Write("<script>window.close();</script>");
我不是要关闭,而是现在他自己自动关闭,导致不能正常下载 Response.Write("<script>window.close();</script>");
作者: austo 发布时间: 2011-12-16
要不,重定向,指定这个文件吧
作者: MSDNXGH 发布时间: 2011-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28