1. 程式人生 > >ASP.NET Response 下載文件

ASP.NET Response 下載文件

下載 flush length ati span content new nco ade

  private void DownLoad(string fileName, string path)
        {
            FileInfo fi = new FileInfo(path);

            if (fi.Exists)
            {
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Buffer 
= true; Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.AddHeader("Content-Length", fi.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream
"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.WriteFile(path); Response.Flush(); Response.End(); } } private void DownLoad2(string fileName, string path) { FileInfo fi
= new FileInfo(path); if (fi.Exists) { Response.Clear(); Response.Buffer = true; Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.ContentType = "application/unknow"; Response.TransmitFile(path); Response.End(); } }

ASP.NET Response 下載文件