当前位置:编程学习 > C#/ASP.NET >>

导出txt时的乱码问题!!!

--------------------编程问答-------------------- 这么复杂啊 --------------------编程问答-------------------- 一般来说 TXT在WINDOWS是 GB2312编码


HttpContext.Current.Response.Clear();
        string FileName = "Test.txt";
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "GB2312";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.GetEncoding("GB2312")).ToString());
        HttpContext.Current.Response.ContentType = "application/ms-text";
        System.IO.StringWriter sw = new System.IO.StringWriter();

        sw.WriteLine(":%、_、#等");

        HttpContext.Current.Response.Write(sw.ToString());
        sw.Close();
        HttpContext.Current.Response.End(); --------------------编程问答-------------------- 顶起,请帮忙!!! --------------------编程问答-------------------- ... --------------------编程问答--------------------
HttpContext.Current.Response.Charset = "UTF-8"; //这里是UTF-8
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;//这里是UTF-7,即ASCII

可能问题在这里吧。 --------------------编程问答-------------------- 谢谢楼上,我试过了,不是这的问题!

主要是特殊字符导出后全成了乱码,晕了!!! --------------------编程问答-------------------- 编码,一会8一会7的 我看也是这问题 --------------------编程问答-------------------- 着急啊。。。

为什么呢??? --------------------编程问答--------------------
看不懂
--------------------编程问答--------------------
引用 7 楼 xfreyes 的回复:
编码,一会8一会7的 我看也是这问题


应该是编码的问题。好好看看。我在做winform的程序时,就遇到过这个问题。 --------------------编程问答-------------------- 统一编码,建议用gb2312. --------------------编程问答-------------------- 应该都用utf-8吧, --------------------编程问答-------------------- utf-8 --------------------编程问答-------------------- 记事本在Windows上默认是ANSI编码!!如果不存在多语言问题,可以gb2312,不需要UTF-8 --------------------编程问答-------------------- 等待中。。。 --------------------编程问答-------------------- 顶
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,