asp.net在新页面中查看pdf

时间:2013-06-04 05:00:27

标签: c# asp.net pdf telerik

以下是我上传和打开PDF文档

的代码
<asp:LinkButton ID="linkButton" runat="server"    
onclick="linkButton_Click">Show PDF</asp:LinkButton>  
   <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"   
     MultipleFileSelection="Disabled"  
     MaxFileInputsCount="1" Width="230px">
  </telerik:RadAsyncUpload>

protected void linkButton_Click(object sender, EventArgs e)
      {
        if (RadAsyncUpload1.UploadedFiles.Count != 0)
        {
            byte[] _myfile = null;
            UploadedFile _file = RadAsyncUpload1.UploadedFiles[0];
            _myfile = new byte[_file.InputStream.Length];
            _file.InputStream.Read(_myfile , 0, (int)_file.InputStream.Length);
            Response.ClearHeaders();
            Response.Clear();
            Response.AddHeader("Content-Type", "application/pdf");
            Response.AddHeader("Content-Length", _fileItenary.Length.ToString());
            Response.AddHeader("Content-Disposition", "inline; filename=sample.pdf");
            Response.BinaryWrite(_fileItenary);
            Response.Flush();
            Response.End();
        }
    }

此代码正常运行,可以在浏览器中显示我上传的pdf 但是,pdf文件显示在同一页面(相同的标签) 点击我的Show PDF链接后,我想在新页面(新标签页)中查看我的pdf 请帮助我,谢谢:)

1 个答案:

答案 0 :(得分:3)

您可以在客户端使用类似的内容进行操作

 OnClientClick="aspnetForm.target ='_blank';"/

 <script type="text/javascript">
    function OpenWindow()
    {
      window.open('nameofyourpage.aspx','_blank','height=450,width=500,scrollbars=0,location=1,toolbar=0');
    }
  </script>

  OnClientClick="OpenWindow()`enter code here`"/