首页 新闻 会员 周边

ReportViewer控件在FireFox下,导出的文件名是乱码

0
悬赏园豆:10 [已解决问题] 解决于 2018-09-10 14:03

平台:VS2012
ReportViewer控件设置导出文件的文件名:this.CustomReportViewer.LocalReport.DisplayName = "测试文件";
在IE和Chrome浏览器下,导出没有问题,但是在FireFox在导出的文件名全是乱码,请问怎么解决??(自己写的导出文件名是正常的,就是用控件自带的导出功能导出的文件名是乱码)

CaptainTina的主页 CaptainTina | 初学一级 | 园豆:3
提问于:2015-09-22 11:39
< >
分享
最佳答案
0

我可以给你一个帖子不知道你有兴趣看看不

http://blogs.msdn.com/b/ieinternals/archive/2010/06/07/content-disposition-attachment-and-international-unicode-characters.aspx

收获园豆:10
稳稳的河 | 老鸟四级 |园豆:4216 | 2015-09-23 10:16

给你看2种浏览器的编码格式

在IE下
URLEncoder.encode(srcFileName,"utf-8");
srcFileName = new String(srcFileName.getByte("utf-8"), "iso-8859-1");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + srcFileName);
火狐中避免乱码:
srcFileName = new String(srcFileName.getByte("utf-8"), "iso-8859-1");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + srcFileName);

现在问题就找到了,如果你想解决所以浏览器的编码问题,建议看上面的帖子,我提供一个IE与FireFox的给你,先解决你的问题:

iE:

if (Request.UserAgent.ToLower().IndexOf("msie") > -1)

{
    downloadfilename = HttpUtility.UrlPathEncode(downloadfilename);
}

FireFox:不去编码,设置Content-Disposition response header

if (Request.UserAgent.ToLower().IndexOf("firefox") > -1)
{
    Response.AddHeader("Content-Disposition", "attachment;filename=\"" + downloadfilename + "\"");
}
else
{
    Response.AddHeader("Content-Disposition", "attachment;filename=" + downloadfilename);
}

 

稳稳的河 | 园豆:4216 (老鸟四级) | 2015-09-23 10:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册