Analytics

2012年4月24日 星期二

[ASP.NET]解決 匯出檔案時,檔名為亂碼的問題(Solve the problem of garbled file name when you export a file)


問題
匯出檔案時,檔名為亂碼的問題



解決方法
string saveName = “myExcel.xls”;
var savePath = AppDomain.CurrentDomain.BaseDirectory + "ExportExcel\\";
Byte[] binaryData = File.ReadAllBytes(savePath + saveName);
Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Expires = 0;
Response.Buffer = true;
Response.HeaderEncoding = System.Text.Encoding.Default;Response.ContentType = "application/octet-stream";
Response.ContentType = "application/vnd.xls";
Response.AddHeader("content-disposition", "attachment;filename=" + saveName);
Response.AddHeader("Content-length", binaryData.Length.ToString());
Response.BinaryWrite(binaryData);
Response.End();

沒有留言:

熱門文章