C# 字符流返回文件下载时 文件中文名乱码处理
来源:互联网 发布:淘宝天下网商店小二 编辑:程序博客网 时间:2024/06/04 20:50
如下在后台代码HttpContext.Current.Response返回文件流前做如下处理即可:
var fileName = "中文文件名.doc";
string modPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);if (!System.IO.File.Exists(modPath))
return;
try
{
FileInfo fileinfo = new FileInfo(modPath);
HttpContext.Current.Response.Clear(); //清除缓冲区流中的所有内容输出
HttpContext.Current.Response.ClearContent(); //清除缓冲区流中的所有内容输出
HttpContext.Current.Response.ClearHeaders(); //清除缓冲区流中的所有头
HttpContext.Current.Response.Buffer = true; //该值指示是否缓冲输出,并在完成处理整个响应之后将其发送
//在如下对中文转码
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(fileName));HttpContext.Current.Response.AddHeader("Content-Length", fileinfo.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary");
HttpContext.Current.Response.ContentType = "application/unknow";
//获取或设置输出流的 HTTP MIME 类型
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
HttpContext.Current.Response.AddHeader("Accept-Language", "zh-cn");
//获取或设置输出流的 HTTP 字符集
HttpContext.Current.Response.TransmitFile(modPath);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
//
}阅读全文
0 0
- C# 字符流返回文件下载时 文件中文名乱码处理
- 文件下载时中文名乱码
- 下载时的中文名文件乱码
- Firefox下载文件时中文名乱码问题
- Firefox下载文件时中文名乱码问题
- firefox下载中文名文件乱码
- Struts2文件下载中文名乱码
- 下载文件:中文名乱码问题
- asp.net 下载文件 中文名乱码
- Android 文件下载中文名乱码的解决办法
- 下载文件中文名出现乱码 java
- javaweb文件下载中文名乱码问题
- java下载文件的时候中文名乱码
- Java文件下载中文名不显示&乱码
- Android 文件下载中文名乱码的解决办法
- 彻底解决中文名文件下载和下载文件内容乱码问题!!!!!
- 彻底解决中文名文件下载和下载文件内容乱码问题!!!!!
- 保存中文名文件乱码
- 虚表(C++)virtual table
- activemq的三种基本通信方式总结 点对点 发布订阅 请求应答
- 【GDOI2018模拟7.8】质数
- Poker Ⅱ 机械键盘使用说明书
- linux内核空间和用户空间详解
- C# 字符流返回文件下载时 文件中文名乱码处理
- mysql 执行流
- networkmutilpledemoforhttpurlconnection 一个综合案例
- 二叉树复习
- ActiveMQ之TemporaryQueue和TemporaryTopic
- MyBatis的第一个HelloWorld小例子(不用接口)
- gcc编译选项
- ActiveMQ请求和应答模式
- 阿里面试问题(C++方向)