C# 下載檔案 - [檔名亂碼問題]
context.Response.ContentType = "application/octet-stream";
string filename = HttpUtility.UrlPathEncode("中文檔名.ppt");
context.Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + "\";");
byte[] data = (byte[])dt.Rows[0]["Data"];
context.Response.AddHeader("Content-Length", data.Length.ToString());
context.Response.BinaryWrite(data);
context.Response.End();
由於FireFox不會發生,可加上下面的code避開(請參考資料來源)
if (Request.Browser.Browser == "IE") {
fileName = Server.UrlPathEncode(fileName);
}
留言
張貼留言