来源:http://blog.csdn.net/nvhaixx/article/details/14451373
aspx页面代码
1 <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="4444_pdfLoad.aspx.vb" Inherits="WebUI._pdfLoad" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml" > 6 <head runat="server"> 7 <title>PDF文件</title> 8 </head> 9 <body> 10 <form id="form1" runat="server"> 11 <div style ="overflow:auto "> 12 <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="100%" height="100%" border="0" top="-10" name="WebBrowser"> 13 <param name="toolbar" value="false" /> 14 <param name="_Version" value="65539" /> 15 <param name="_ExtentX" value="20108" /> 16 <param name="_ExtentY" value="10866" /> 17 <param name="_StockProps" value="0" /> 18 <param name="SRC" value="<%=filename %>" /> 19 </object> 20 </div> 21 </form> 22 </body> 23 </html>
后台代码:(VB.NET代码)
1 Imports System.IO 2 3 Partial Public Class _pdfLoad 4 Inherits System.Web.UI.Page 5 6 Public filename As String 7 8 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 9 10 filename = "../../DownLoadFile/" + HttpUtility.UrlDecode(Request.QueryString("PDFFile")) 11 12 If File.Exists(filename) = False Then 13 Me.Page.ClientScript.RegisterStartupScript(Me.GetType, "msg", "<script language=‘javascript‘>alert(‘文件不存在!‘);window.opener=null;window.close();</script>") 14 Exit Sub 15 End If 16 17 End Sub 18 19 End Class
注: 此处的 filename必须使用相对路径,不可以使用server.mappath之类的绝对路径。
如果使用的是绝对路径,则在xp下的本地运行可以使用,发布后不可以使用!
时间: 2024-10-13 01:13:47