在根文件夹外的弹出窗口中打开pdf [英] open pdf in pop up window outside root folder

查看:119
本文介绍了在根文件夹外的弹出窗口中打开pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

如何在新的弹出窗口中打开.pdf文件?我有这段代码:

Hi
How do you open a .pdf file in a new pop up window? I have this code:

string url = @"D:\Folder\PICTURES\Enigma.pdf"
System.Windows.Forms.MessageBox.Show(url);
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url));





它会打开一个弹出窗口,但PDF文件没有显示。



谢谢,



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

Thanks,

推荐答案

你正在做一些没有意义但不起作用的事情:显示Windows消息框。在服务器端。没有人可以关闭对话框,甚至是......它只会阻止HTTP响应的进一步处理和HTTP响应的生成,并且可能会超时。



现在,D:\Folder \ PICTURES \ Enigma.pdf不是URL。我甚至要解释这个区别吗?任何普通的Web用户,甚至不是软件开发人员,都有一定的了解。此外,Web应用程序在沙盒环境中执行,并且无法直接访问服务器主机的文件系统。它只能访问配置到站点的根目录下的文件。没有使用硬编码文件路径的情况。



最后,PDF不是W3标准的一部分,所以你不能假设PDF会无论如何都要在浏览器窗口中呈现。它需要一个单独的查看器,可以安装或不安装为浏览器插件。这种插件是可选的。因此,最好简单地将锚点指向您的PDF文件(使用 href br mode =hold/>这样,用户将获得一个选项在浏览器中查看此文件,但仅在安装了PDF插件时才能使用默认PDF查看器查看该文件(如果已为您的系统配置),或者下载文件,这是非常合理的,因为用户始终可以稍后查看该文档。最好不要偏离这个强大的架构。



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

—SA


这篇关于在根文件夹外的弹出窗口中打开pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆