ASP 在网页中 打开PDF文件
2015-08-31 17:44
639 查看
发送URL:
if (File.Exists(p_strUrl))
{ //Server.UrlEncode(path)
this.Page.RegisterStartupScript("", "<script>window.open('XXX.aspx?pdfPath=" + Server.UrlEncode(p_strUrl) + "')</script>");
return;
}
else
{
this.Page.RegisterStartupScript("", "<script>alert('未找到PDF文件!')</script>");
return;
}
跳转的界面(XXX.aspx?)就收URL:
pdfPath = Server.UrlDecode(Request["pdfPath"].ToString());//获取传来的路径
try
{
FileStream fs = File.Open(pdfPath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
if (fs.Length > 0)
{
byte[] bfBuf = new byte[fs.Length];
bfBuf.Initialize();
fs.Read(bfBuf, 0, (int)fs.Length);
Response.ContentType = "application/PDF";
Response.OutputStream.Write(bfBuf, 0, bfBuf.Length);//以流的形式显示在网页上
// Response.ContentType =
// Response.BinaryWrite(bfBuf);
Response.End();
fs.Close();
}
}
finally
{
;
}
if (File.Exists(p_strUrl))
{ //Server.UrlEncode(path)
this.Page.RegisterStartupScript("", "<script>window.open('XXX.aspx?pdfPath=" + Server.UrlEncode(p_strUrl) + "')</script>");
return;
}
else
{
this.Page.RegisterStartupScript("", "<script>alert('未找到PDF文件!')</script>");
return;
}
跳转的界面(XXX.aspx?)就收URL:
pdfPath = Server.UrlDecode(Request["pdfPath"].ToString());//获取传来的路径
try
{
FileStream fs = File.Open(pdfPath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
if (fs.Length > 0)
{
byte[] bfBuf = new byte[fs.Length];
bfBuf.Initialize();
fs.Read(bfBuf, 0, (int)fs.Length);
Response.ContentType = "application/PDF";
Response.OutputStream.Write(bfBuf, 0, bfBuf.Length);//以流的形式显示在网页上
// Response.ContentType =
// Response.BinaryWrite(bfBuf);
Response.End();
fs.Close();
}
}
finally
{
;
}
相关文章推荐
- (转)asp.net中,<%#%>,<%=%>和<%%>分别是什么意思,有什么区别
- ASP.NET MVC必知必会知识点总结(二)
- discuz之ucenter同步登录asp.net网站
- raspbian 配置AP热点
- ASP.NET中使用Ajax
- asp中将文本框内的日期转换成datetime类型的数据
- asp中将文本框内的日期转换成datetime类型的数据
- Aspose.words介绍
- java错误-The prefix "aop" for element "aop:aspectj-autoproxy" is not bound.
- Aspose.Words如何在文档中添加水印
- Aspose.Words使用教程之如何在文档中添加水印
- java错误-java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around
- 用casperjs截取任意网页区域
- phantomjs/casperjs动态传入参数
- Ubuntu安装Casperjs
- Spring AOP编程中--@aspect 标签,切面编程
- Asp.net自动生成三层代码视频教程
- ASP.NET中身份验证
- win2003中iis与asp设置Session会话过期时间的问题
- 安装ASP.net mvc3 Installation failed with error code: (0x80070643), "安装时发生严重错误 "