ASP 在网页中 打开PDF文件

发送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

            {

                ;

            }

    原文作者:cddchina
    原文地址: https://blog.csdn.net/cddchina/article/details/48137211
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞