在服务器上生成文件的内容..给客户端直接下载.文件必需是unicode编码格式,代码.string fileName = "aaaa.csv";
StringWriter sw = new StringWriter();
sw.WriteLine("abs中文");
this.Response.Clear();
this.Response.Buffer = true;
this.Response.Filter.Close();
this.Response.ContentEncoding = System.Text.Encoding.Unicode;
this.Response.Charset = "Unicode";
this.Response.AddFileDependency(fileName);
this.Response.ContentType = "text/csv";
this.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
this.Response.Write(sw);
this.Response.End();
sw.Close();
如果字符串里没有中文,下载下来的文件就是unicode编码的文件,如果有中文就不是,中文也变在乱码.请教这个要怎么解决?
StringWriter sw = new StringWriter();
sw.WriteLine("abs中文");
this.Response.Clear();
this.Response.Buffer = true;
this.Response.Filter.Close();
this.Response.ContentEncoding = System.Text.Encoding.Unicode;
this.Response.Charset = "Unicode";
this.Response.AddFileDependency(fileName);
this.Response.ContentType = "text/csv";
this.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
this.Response.Write(sw);
this.Response.End();
sw.Close();
如果字符串里没有中文,下载下来的文件就是unicode编码的文件,如果有中文就不是,中文也变在乱码.请教这个要怎么解决?
解决方案 »
- 一个关于文件路径的问题
- ASP.net的ASHX問題
- 请教usercontrol 不触发界面的问题
- 为什么同样一个md5算法在asp.net中和在window from里面 得到值不一样呐?
- 如何理解“把xml文件以流的方式直接POST到我们系统的某个http接口中”然后解析,入库???
- 怎样写sql语句:查找库中的某个时间已距今超过三天的所有记录?
- 求一个sql语句~~~
- 郁闷中,搞asp.net开发好,还是搞winforms开发好!!
- 帮帮我, 这是什么错误呀?
- 学习dotNET技术, 本人强烈推荐的一个网站
- 怎么将合并了表头的Grid数据,原样导出至Excel呀?大家帮忙呀!急急急----
- Asp.net2005 连接一个文件夹下面的多个access数据库100分长期在线
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />2,html页面(aspx页面),及cs文件保存时采用的编码为utf-8这样,一般不会有问题.
内容如下
system.web>
<globalization fileEncoding="gb2312" requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" uiCulture="zh-CN"/>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true">
1
开始>>附件>>记事本>>随便敲几个字母,比如abcde.然后点保存,存为a.txt(默认为ansi)
2
开始>>附件>>记事本>>随便敲几个字母,比如abcde.然后点保存,不要急着保存,在保存对话框那里,编码那里选utf-8,再存为b.txt用记录本分别打开a.txt和b.txt你看到的内容是一样的.
用ultra eidt等其它工具,以二进制方式查看文件,你看到的内容是不一样的.做完我上面说的, 再回头看我在4楼的回贴,你就明白我的意思了.