平台:VS2012
ReportViewer控件设置导出文件的文件名:this.CustomReportViewer.LocalReport.DisplayName = "测试文件";
在IE和Chrome浏览器下,导出没有问题,但是在FireFox在导出的文件名全是乱码,请问怎么解决??(自己写的导出文件名是正常的,就是用控件自带的导出功能导出的文件名是乱码)
我可以给你一个帖子不知道你有兴趣看看不
http://blogs.msdn.com/b/ieinternals/archive/2010/06/07/content-disposition-attachment-and-international-unicode-characters.aspx
给你看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); }