protected void LinkButton5_Click(object sender, EventArgs e)
{
string filename = "xxx.pdf";
//從Server端取得檔案
Stream FileStream;
FileStream = File.OpenRead(Server.MapPath("~/xxx/xxx.pdf"));
downloadBook(filename, FileStream);
}
protected void downloadBook(string filename, Stream FileStream)
{
Byte[] Buf = new byte[FileStream.Length];
FileStream.Read(Buf, 0, int.Parse(FileStream.Length.ToString()));
FileStream.Close();
//準備下載檔案
Response.ClearHeaders();
Response.Clear();
Response.Expires = 0;
Response.Buffer = false;
Response.ContentType = "Application/save-as";
Response.Charset = "utf-8";
//透過Header設定檔名
Response.AddHeader("Content-Disposition", "Attachment; filename=" + HttpUtility.UrlEncode(filename));
Response.BinaryWrite(Buf);
Response.End();
}
留言列表