Display PDF (or other file) in new browser window

G

Guest

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.
 
R

Raterus

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%2bujPU1unHMccZh0L7%2bgEM%2bdKHdj" id="scnPreview_hypFullScreen" target="_NEW">Open FullScreen Preview</a>

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

--Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top