2009-02-19 [ASP.NET]下載一個動態產生的檔案 4650 0 ASP.NET 摘要:下載一個動態產生的檔案 以為文字檔為例private void DownloadFile(string fileName, string strBody) { // 處理中文亂碼 fileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8); Response.ClearHeaders(); Response.Clear(); Response.Expires = 0; Response.Buffer = true; Response.AddHeader("Accept-Language", "zh-tw"); Response.AddHeader("content-disposition", "attachment;filename=" + fileName); Response.ContentType = "text/plain"; Response.Write(strBody); Response.End(); }其它支援檔案類型可參考 ContentType參考資料:contentType.rarList of HTTP headers ASP.NET 回首頁