输出PDF文档到ASP.NET页面
来源:互联网 发布:游族网络电脑官网 编辑:程序博客网 时间:2024/05/23 13:25
protected void Page_Load(object sender, EventArgs e)
{
try
{
//query the pdf path
string pdfna = this.Request.QueryString["pdf"];
if (pdfna == null)
throw new Exception("This page can not be accessed directly");
string pdf = "Reports//" + pdfna;
pdf = Server.MapPath(pdf);
//read all bytes
if (File.Exists(pdf) == false)
throw new Exception("This report is not created");
FileStream fs = File.Open(pdf, FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
//write to response
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "filename=" + pdfna);
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
Response.Flush();
Response.Close();
Response.End();
}
}
- 输出PDF文档到ASP.NET页面
- 输出PDF文档到ASP.NET页面
- Asp.net页面输出到EXCEL (转)
- Asp.Net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- Asp.net页面输出到EXCEL
- Asp.Net页面输出到EXCEL
- json入门
- XP 和2003的Lsass进程中明文密
- ASP.NET MVC使用感言
- USBHID设备报告描述符详解(转帖)
- [悠悠农夫]log分析
- 输出PDF文档到ASP.NET页面
- what is the difference between the setTimeout and setInterval
- windows的一些小技巧
- 2010カレンダー
- 在主线程中慎用WaitForSingleObject (WaitForMultipleObjects)
- 第一个D3D代码
- SQL Server 只想对备份的文件恢复数据文件,不恢复日志文件
- C# 递归算法!
- wifi scan mode