469,631 Members | 1,734 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Display PDF (or other file) in new browser window

We have a situation where we display PDF files through IE via a method in our code-behind as follows

protected void displayPDF(string exePath, string filePath
{
// exePath is the Request.CurrentExecutionPath and we trim off the actual ASPX page designation an
// replace that with the "filePath" which represents the path and PDF that we want to display
string fullPath = exePath.Substring(0, exePath.LastIndexOf('/'))
fullPath += filePath
// Next, we create a physical path from the virtual pat
fullPath = Server.MapPath(fullPath)
// Create a FileInfo object and write it to the response
FileInfo theFile = new FileInfo(fullPath)
Response.Clear()
Response.ContentType = "application/pdf"
Response.Flush()
Response.WriteFile(theFile.FullName)
Response.End()
This code works and displays the PDF through IE in the browser. It also keeps our PDF secure because bookmarking the page simply bookmarks the ASPX that generates this file and that is protected by our custom security scheme. (Thanks to members of the newsgroup for pointing me in the right direction about this - an earlier post.

Now, we have an additional requirement to do this display, but to do it in a new and separate browser window from the one that originates the request. So, the original browser window, with link buttons that call the method above remains behind the new browser window with the displayed PDF

Is it possible? And if so, how

Thanks.
Nov 18 '05 #1
1 9111
as far as I know, there is no way on the server to tell the browser to open a new browser window, this has to be done by the client, through a hyperlink with an appropriate target attribute set.

Here is how I've tackled this problem in the past. I created a download.aspx page, which takes on parameter in the querystring, and encrypted filepath. The page unencrypts it, and if it corresponds to a downloadable file, push it out to the user.

So basically I have a hyperlink that looks like this on a main page

<a href="../shared/download.aspx?file=miuDGJwM%2f8jzcDCEYBV%2b%2bujPU 1unHMccZh0L7%2bgEM%2bdKHdj" id="scnPreview_hypFullScreen" target="_NEW">Open FullScreen Preview</a>

The encryption is 3DES, so I would say it is pretty secure.

--Michael
"chazmanian" <an*******@discussions.microsoft.com> wrote in message news:35**********************************@microsof t.com...
We have a situation where we display PDF files through IE via a method in our code-behind as follows:

protected void displayPDF(string exePath, string filePath)
{
// exePath is the Request.CurrentExecutionPath and we trim off the actual ASPX page designation and
// replace that with the "filePath" which represents the path and PDF that we want to display.
string fullPath = exePath.Substring(0, exePath.LastIndexOf('/'));
fullPath += filePath;
// Next, we create a physical path from the virtual path
fullPath = Server.MapPath(fullPath);
// Create a FileInfo object and write it to the response.
FileInfo theFile = new FileInfo(fullPath);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Flush();
Response.WriteFile(theFile.FullName);
Response.End();
}

This code works and displays the PDF through IE in the browser. It also keeps our PDF secure because bookmarking the page simply bookmarks the ASPX that generates this file and that is protected by our custom security scheme. (Thanks to members of the newsgroup for pointing me in the right direction about this - an earlier post.)

Now, we have an additional requirement to do this display, but to do it in a new and separate browser window from the one that originates the request. So, the original browser window, with link buttons that call the method above remains behind the new browser window with the displayed PDF.

Is it possible? And if so, how?

Thanks.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by santiago538 | last post: by
3 posts views Thread by VMI | last post: by
10 posts views Thread by A.M | last post: by
3 posts views Thread by Rich Wallace | last post: by
15 posts views Thread by Matt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.