1. 程式人生 > >將檔案以流的形式另存為下載

將檔案以流的形式另存為下載

string strFile = Server.MapPath("/images/526763.pdf");
using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("
Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("base.pdf", System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); }