In its most simplest interpretation, to open a new window or tab, the hyperlink to the page should have the target
attribute set to "_blank"
.
<a href="GeneratePDF.aspx" target="_blank">Link to open PDF in new window</a>
Or you could create some Javascript that opens a new window instead. Make sure you call the Javascript function somewhere on the page.
<script type="text/javascript">
function loadPDF() {
window.open('GeneratePDF.aspx','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
</script>
Or this code will inform the web browser that the file is a download (rather than a page to view inside the browser window). I think this is the best approach because the user gets the choice of Opening or Saving the PDF. So this does not do what you're asking for, but you might think it's better.
private void OpenPDF(string downloadAsFilename)
{
ReportDocument Rel = new ReportDocument();
Rel.Load(Server.MapPath("../Reports/Test.rpt"));
BinaryReader stream = new BinaryReader(Rel.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + downloadAsFilename);
Response.AddHeader("content-length", stream.BaseStream.Length.ToString());
Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)));
Response.Flush();
Response.Close();
}