Click here to Skip to main content
15,796,456 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do you open a .pdf file in a new pop up window? I have this code:
string url = @"D:\Folder\PICTURES\Enigma.pdf"
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>'{0}');</script>", url));

It does open a popup window but the PDF file is not displaying.

Sergey Alexandrovich Kryukov 2-Oct-14 6:32am    
Sorry, this is complete gibberish which tells me that you are not ready to do ASP.NET programming at all, needs first to come to some understanding of how Web works. So far, you have no clue. I'll try to explain in the answer, but it cannot be a substitute for learning it from scratch.

1 solution

You are doing something which makes no sense and won't work: show Windows message box. On the server side. There won't be anyone who could close the dialog, and even it was… it will just block further processing of the HTTP response and generation of the HTTP response and probably will time out.

Now, "D:\Folder\PICTURES\Enigma.pdf" is not URL. Do I even have to explain the difference? Any regular Web user, even not a software developer, has some understanding. Besides, a Web application is executed in a sandboxed environment and does not have direct access to the file system of the server's host. It can only access files under the root directory configured to the site. There are no cases when using hard-coded file paths can be used.

Finally, PDF is not a part of W3 standard, so you cannot ever assume that PDF will be rendered in a browser window anyhow. It requires a separate viewer, which may or may not be installed as a browser plug-in. Such plug-in is optional. So, it's the best to simply put an anchor pointing to your PDF file (using the hrefbr mode="hold" />This way, the user will get an option to view this file in browser, but only if a PDF plug-in is installed, to view it using a default PDF viewer, if so is configured for your system, or download the file, which is quite reasonable, because the user can always view the document later. It's the best not to deviate from this robust schema.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900