惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - zhangsir

.net 项目 调用webservice 出错,异常信息:对操作“xxx”的回复消息正文进行反序列化时出错。解决方案。 手机版web相关meta配置 网页中点击运行执行代码 js 在页面上模拟多选,蚂蚁线线框 C# 检测程序运行时间的方法,Stopwatch类 js获取url参数值 flash as2 简易手写板,带擦除功能 flash as2 BitmapData应用之 ---- 画双线 svn(版本管理) 去掉(清理)版本信息的方法 sql 数据库显示 正在恢复 as3中parent访问属性所牵涉的强制类型的问题 [AS3]URLVariables传入URL编码字符串时的一些官方无文档的原则 sql 日期 、时间相关 100万个不重复的8位的随机数 flash 中实现斜切变型 使用UpdatePanel 局部刷新出现中文乱码的解决方法!! - zhangsir - 博客园 loaded AS2 swf call function in AS3 holder - zhangsir Rewrite the master page form action attribute in asp.net 2.0 sql2000 跨服务器复制表数据
C#导出csv文件 支持中文的解决方案
zhangsir · 2013-12-24 · via 博客园 - zhangsir
        #region 导出CSV下载
        string exportFileName = "Export" + DateTime.Now.ToString("yyyyMMddHHmmss");
        System.Web.HttpContext context = System.Web.HttpContext.Current;
        StringBuilder sb = new StringBuilder();
        sb.Append("FirstName,LastName,PhoneNo.,State,TimeZone,ZipCode\n");
        for (int i = 0; i < result.PhoneList.Count; i++)
        {
            sb.Append(result.PhoneList[i].FirstName + "," + result.PhoneList[i].LastName + "," + result.PhoneList[i].Phone + "," + result.PhoneList[i].State + "," + result.PhoneList[i].TimeZone + "," + result.PhoneList[i].ZipCode + "\n");
        }
        StringWriter sw = new StringWriter(sb);
        sw.Close();
        context.Response.Clear();
        /* 
         * Acme 2012-07-04 edit 
         *  
        context.Response.Charset = "gb2312"; 
        context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 
        context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // "application/octet-stream"; //"application/vnd.ms-excel"; //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet                   
        //context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName)); 
        */
        //below is new writing  
        context.Response.Charset = "UTF-8";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentType = "text/csv";
        //主要是下面这一句
        context.Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });
        context.Response.Write(sw);
        context.Response.AppendHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(exportFileName + ".csv", System.Text.Encoding.UTF8).Replace("+", "%20"));
        //context.Response.OutputStream.Write(fileData, 0, fileData.Length);  
        context.Response.Flush();
        context.Response.End();
        #endregion