user773456
user773456

Reputation: 651

Open PDF File in new Window?

Hi I'm stuck in the next situation, I need to open a pdf file which I uploaded to sever first. I've tried the following code:

string Servidor = Request.Url.GetLeftPart(UriPartial.Authority);
var fullUrl  = Servidor + Session["strUrl"];

var NewProcess = new System.Diagnostics.Process();
NewProcess.StartInfo.FileName = fullUrl;
NewProcess.Start();

This code works fine when I'm in localhost, but when I deploy my web application, it doesn't work. Is there any other solution to accomplish this?

Upvotes: 1

Views: 5707

Answers (3)

Polo Guy
Polo Guy

Reputation: 47

Use this code. This works like a champ.

Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = outputPdfFile;
process.Start();

Upvotes: 0

TFD
TFD

Reputation: 24534

In your generated html you need a "target" attribute on the "a" tag with a window name, or more generically "_blank" to open a new window

e.g.

<a href="document.pdf" target="_blank">Open document in a new window</a>

or in pure asp.net

<asp:HyperLink id="hyperlink1" NavigateUrl="document.pdf" Target="_blank" Text="Open document in a new window"  runat="server"/>  

Upvotes: 2

Jakob Gade
Jakob Gade

Reputation: 12419

You can't open a PDF by starting a new process on a remote server. You have to create a link on a webpage thats hosted on the server which points to the pdf you want to open (which also should be hosted on the web server).

<a href="file.pdf">Open</a>

Upvotes: 1

Related Questions