Asp.net 解决下载乱码问题,支持火狐、IE、谷歌等主流浏览器
2024-08-27 09:45:47
public static void DownFileStream(MemoryStream ms, string fileName)
{
if (ms !=Stream.Null)
{ if (HttpContext.Current.Request.UserAgent != null && HttpContext.Current.Request.UserAgent.ToUpper().IndexOf("FIREFOX", StringComparison.Ordinal) != -)
{
fileName = "=?UTF-8?B?" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileName)) + "?=";
}
else
{
fileName = System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
if (fileName != null) fileName = fileName.Replace("+", "%20");
}
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.xls",fileName));
HttpContext.Current.Response.AddHeader("Content-Length", ms.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary");
HttpContext.Current.Response.ContentType = "application/octet-stream;charset=utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
ms.Close();
ms.Dispose();
}
}
最新文章
- 锐捷与Vmare网络冲突解决办法
- spring 的IoC的个人理解
- codeforces gym 100694 M The Fifth Season (巴什博奕)
- java多线程-Condition
- SVN更新、清理乱码解决
- 用VBS脚本发邮件
- javaWeb中的/路径问题
- [AngularJS] Services, Factories, and Providers -- Service vs Factory
- C# 开机自动启动程序
- Windsock套接字I/O模型学习 --- 第一章
- SQLSERVER设置行号
- Django学习(四)---Admin配置
- Myeclipse 配置Tomcat 出现 “Value must be an existing directory”错误
- HttpClient4.2 Fluent API学习
- 用C语言绘制一条标准的余弦曲线
- 微信小程序-制作简易豆瓣笔记
- MySQL数据库之安装
- 如何使QLineEdit禁止编辑
- a 超链接标签
- Eclipse编辑JS响应慢,复制粘贴卡顿的解决方案