简体   繁体   English

在新的 Window 中打开 PDF 文件?

[英]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.嗨,我陷入了下一种情况,我需要打开一个 pdf 文件,我先上传到服务器。 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.当我在本地主机中时,此代码工作正常,但是当我部署我的 web 应用程序时,它不起作用。 Is there any other solution to accomplish this?有没有其他解决方案来实现这一点?

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在您生成的 html 中,您需要“a”标签上的“target”属性,名称为 window,或更通用的“_blank”,以打开新的 window

eg例如

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

or in pure asp.net或纯 asp.net

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

You can't open a PDF by starting a new process on a remote server.您无法通过在远程服务器上启动新进程来打开 PDF。 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).您必须在托管在服务器上的网页上创建一个链接,该链接指向您要打开的 pdf(也应托管在 web 服务器上)。

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

Use this code.使用此代码。 This works like a champ.这就像一个冠军。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM