2015-08-24 108 views
0

我寫了這個代碼用於出口的GridView到Excel:導出到Excel文件名

System.Web.HttpContext.Current.Response.Clear(); 
Response.Buffer = true; 
Response.ClearContent(); 
Response.ClearHeaders(); 
Response.Charset = System.Text.Encoding.UTF8.EncodingName; 
Response.ContentEncoding = System.Text.Encoding.UTF8; 
Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble()); 
string FileName = Title + ".xls"; 
StringWriter strwritter = new StringWriter(); 
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.ContentType = "application/vnd.ms-excel"; 
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName); 

,但文件名不針對非英語名稱(如阿拉伯語)正確顯示。我如何將文件保存爲非英文名?

enter image description here

感謝

回答

0

裹文件名以

Server.UrlEncode 

例如:

string FileName = Server.UrlEncode(Title + ".xls"); 

和它的作品!!!!