摘要:[ASP.NET] 強迫另存新檔
解決方法:
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Accept-Language", "zh-tw");
//attachment = 此頁為附件檔,預設為 inline ,會直接顯示在網頁上
Response.AddHeader("content-disposition", "attachment; filename=StuCard.mdb");
//若要使用中文檔名
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("製卡機匯出資料") + ".mdb");
//欲輸出的檔案類型
Response.ContentType = "application/ms-access";
//指定欲輸出的實體檔案路徑(Server端)
Response.TransmitFile(Request.ApplicationPath + "/stu/StuCard.mdb");
Response.Flush();
Response.End();
補充:Response.ContentType 類型
'doc' => 'application/msword''exe' => 'application/octet-stream'
'pdf' => 'application/pdf'
'xls' => 'application/vnd.ms-excel'
'ppt' => 'application/vnd.ms-powerpoint'
'jpg' => 'image/jpeg'
'png' => 'image/png'
參考資料:
http://blog.miniasp.com/post/2008/04/ASPNET-Force-Download-File-and-deal-with-Chinese-Filename-correctly.aspx
http://tw.myblog.yahoo.com/frankintaiwan/article?mid=745&prev=757&next=742
http://akilina108.pixnet.net/blog/post/22676493