We help IT Professionals succeed at work.

How Do I Open a PDF File in a New Browser Instance?

I have an ASP.NET 2.0 web application using C# that allows users to locate a particular record and display the associated report file for that record.  The report files are stored as PDF files.  The application currently displays the PDF files in a window using the following code (this is a portion of the code from the GridView_SelectedIndexChanged method):

        Response.ContentType = "application/pdf";
        strDestFile = @"pdfs\" + oFile.Name;
        strDestFile = MapPath(strDestFile);
        Response.WriteFile(strDestFile);
        Response.End();

This displays the PDF correctly, but the specification for the software requires that each PDF file be launched in its own Browser instance, so the user does not need to hit the back button and can view multiple reports onscreen at the same time.

I need to know how to launch each PDF file as an independent browser instance.
Comment
Watch Question

use javascript to open a popup and then load the file in that window
use the code below
<script language="javascript">
 function showPDF( PDFName )
 {
  window.open( "http://myServer.com/MyFolder/" + PDFName );
 }
</script>
.
.
.
<a href="#" onclick="showPDF('123.pdf')">Open 123</a>

Open in new window

Author

Commented:
I don't have an onclick() method to tie this to.

Author

Commented:
Apologies for the terseness of my previous message.  What I'm trying to convey is that I want to use the GridView_SelectedIndexChange() event to a)determine which file to display and b) display the PDF file in a new browser instance.  I'm looking for a way to use the Response object to open the new window.
instead... you could simply use a template column and use the logic to show the file


<asp:gridview id="gvList" runat="server">
.
.
.
 
<itemtemplate>
 <a href='#' onclick="showPDF('<%# Eval("AAA") %>')">Click Here</a>
</itemtemplate>
 
.
.
.
.
 
</asp:gridview>

Open in new window

It seems I threw off the editor with the single and double quotes

<asp:gridview id="gvList" runat="server">
.
.
.
 
<itemtemplate>
 <a href='#' onclick="showPDF('<%# Eval("AAA") %>')">Click Here</a>
</itemtemplate>
 
.
.
.
.
 
</asp:gridview>

Author

Commented:
The GridView is dynamically created and bound to a SqlDataReader, and I am using the AutoGenerateSelectButton property to generate the Select links for each PDF file.  I do not know how to make the modifications you are suggesting to this type of GridView - the columns for the GridView are dynamically created by a stored procedure call, not hard-coded.
Commented:
I ended up rewriting the grid view as a dynamically generated table so I could have multiple links on the page.  I am now opening the PDF files using a separate aspx page (with nothing on it).

Explore More ContentExplore courses, solutions, and other research materials related to this topic.