发送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
{
;
}