最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net 導(dǎo)出到CSV文件亂碼的問題

 更新時間:2010年03月30日 13:19:11   作者:  
導(dǎo)出到CSV文件亂碼的問題,需要的朋友可以參考下。

http://social.microsoft.com/Forums/zh-CN/295/thread/14a833f5-95bf-48ef-b6cf-c6028f338561

string name = System.Configuration.ConfigurationSettings.AppSettings["downloadurl"].ToString();
FileStream fs = new FileStream(name, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));

sw.WriteLine(" 自動編號,姓名,年齡");
foreach (DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"] + "," + dr["vName"] + "," + dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
Response.ContentType = "application/ms-excel";// 指定返回的是一個不能被客戶端讀取的流,必須被下載
Response.WriteFile(name); // 把文件流發(fā)送到客戶端
Response.End();

重點為紅色標記處!

------

string strFile = "FileName" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".csv";

//這一部分替換為你從DataTable/GridView獲取的內(nèi)容
StringBuilder sb = new StringBuilder();
sb.AppendLine("id,name");
sb.AppendLine("1,鄒俊才");
sb.AppendLine("2,才俊鄒");
sb.AppendLine("3,Jon");

StringWriter sw = new StringWriter(sb);
sw.Close();

Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", strFile));
Response.Charset = "gb2312";
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.Write(sw);
Response.Flush();
Response.End();

相關(guān)文章

最新評論

延安市| 苏尼特右旗| 万载县| 德格县| 陇川县| 纳雍县| 平泉县| 鸡西市| 左贡县| 彝良县| 桑植县| 新郑市| 宣恩县| 安福县| 浠水县| 晴隆县| 鹤岗市| 涞水县| 灵丘县| 吉木乃县| 噶尔县| 睢宁县| 商都县| 阿巴嘎旗| 额尔古纳市| 华阴市| 诸城市| 且末县| 南阳市| 崇礼县| 尼木县| 响水县| 连州市| 忻州市| 桂林市| 依安县| 道孚县| 林芝县| 岳西县| 封丘县| 利川市|