ASP.NET 檔案下載

摘要:ASP.NET 檔案下載

 if (string.IsNullOrEmpty(Request["token"]))
            {
                Response.Write("密碼錯誤");
                return;
            }

            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode("DonmaSampleExcelFile" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xls"));

            //設定MIME 標頭
            //可以參考 http://baike.baidu.com/view/160611.htm
            Response.ContentType = "application/octet-stream";
            Response.BinaryWrite(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\ABC\\npoi2.xls"));