如何从Sharepoint页面提示用户输入保存位置? [英] How can I prompt the user for a save location from a Sharepoint page?

查看:122
本文介绍了如何从Sharepoint页面提示用户输入保存位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相关的问题

是否有其他选择或解决方法,以便我可以提示用户输入位置?

更新

我认为这无法尝试保存客户端生成的文件,因为它是通过服务器端生成的(通过iTextSharp).

更新2

通过创建指向文件的链接(如我所做的那样,作为

那么我该如何调用一个明显可调用的对话框来响应链接单击?

如果看到总计和付款总额不匹配;请为两个值输入相同的金额,然后重试."必须重新显示表单(创建一个"show_sections()"函数并在保存按钮运行后调用它)?

解决方案

我浏览了您的其他问题,我只是想确保我们在两件事上很清楚. (如果这里有任何明显的现象,请原谅我,我无意侮辱我,我只是想确保我们在同一页上.)

首先,客户端和服务器.服务器端的任何内容都在用户帐户的上下文中运行,并且相对于其运行的计算机.如果使用服务器端代码说将其保存到桌面",则这是服务器本地进程的桌面,几乎没有任何意义.但是,如果要模拟已登录的用户,则除了将其保存到服务器上已登录用户的桌面 上之外,这可能会起作用.如果客户端和服务器在同一台计算机上运行,​​并且您正在模拟客户端,则这实际上可能完全起作用.也许.

第二,右键单击另存为.右键单击链接时,您正在调用浏览器的内置专有菜单系统.该系统是特定于浏览器和/或OS的,并且未在此处的任何规范中定义.在90年代,您可能已经能够使用VBScript来发送密钥",并使Internet Explorer能够单击"该链接,但是那些日子已经一去不复返了.与此最接近的等效形式是编写一个我想您不想做的插件(并且将是浏览器和/或特定于操作系统的).

第三种 MIME类型.一般来说,每个HTTP响应都包含一个MIME类型,该类型指定服务器发送字节的意图.其中包括text/htmlapplication/pdf之类的东西.当不调用服务器端代码(ASP.Net)时,例如图像和CSS之类的静态文件,甚至是PDF之类的预生成文件,服务器(IIS)都会在列表中查找文件扩展名以确定什么要发送的MIME类型.在客户端,浏览器使用MIME类型来确定要执行的操作.如果它是text/html,则它(可能)呈现HTML.如果为application/pdf,则浏览器将查看MIME类型的列表,以查看是否有任何应用程序注册了该MIME类型.大多数现代浏览器都有内置的PDF渲染器,因此浏览器只是将字节传递到该渲染器上.如果浏览器不知道该MIME,则可能询问操作系统是否知道该MIME并具有可用的注册处理程序,如果可以,它将通过.如果所有操作都失败了(可能是因为像我这样的用户已禁用了该特定的MIME类型),那么浏览器要么只是将这些字节放入下载"文件夹,它就会尝试将这些字节解释为文本,或者提示您保存.

根据 HTTP规范(19.5.1第3段),如果您除了发送Content-Disposition: attachment; filename="fname.ext"标头之外还发送application/octet-stream的MIME类型,则

暗示的建议是用户代理 不应该显示响应,而是直接输入保存响应" 作为..."对话框.

这是您最终要实现的目标,对吧?

在您的情况下,单击PDF链接会绕过ASP.Net,而IIS只会查找文件并发送application/pdf MIME类型.一种解决方法是注销 PDF文件扩展名从系统中.但是,这可能不是最可移植的解决方案.同样,您也可以将文件扩展名更改为application/octet-stream,然后(可能)出现另存为"对话框.

我认为强制另存为"对话框的最佳选择是在服务器端创建某种处理程序,该处理程序将MIME类型和Content Disposition标头强制放入流中,然后传递文件的原始字节.您可以通过几种方式来做到这一点,也许可以使用 IHttpHandler (甚至更好的是here, where I was trying to create a link to the location of the saved file (where the location and filename are taken care of for the user). Unfortunately, the link won't open the file, due to path access denial (as described in Update 4 in the link above).

What I really would rather do, if possible, is prompt the user for a save location (without requiring them to enter into an input text element something like "C:\Bla\Blee"); I don't think, though, that the tried-and-not-so-true (in this case) FileSaveDialog is available to me from a Sharepoint page.

Are there any alternatives or workarounds so that I can prompt the user for a location?

UPDATE

I don't think this will work to try to save the generated file client-side, because it is generated (via iTextSharp) server-side.

UPDATE 2

By creating a link to the file (as I have done, as hown here), I can right-click said link and select "Save Taget As..." and do so (a "Save As" dialog appears, and I can save the file wherever I want). This being the case, there must be a way to invoke that same dialog programatically so that, instead of the user having to right-click, and then select a menu item ("Save Target As..."), they can simply mash the link and up pops, weasel-like, the "Save As" dialog.

So how can I invoke that obviously invokable dialog in response to a link click?

If see "Total and Payment Total do not match; Please enter the same amount for both values and try again." must redisplay the form (make a "show_sections()" function and call it after the save button runs)?

解决方案

I browsed through your other questions and I just want to make sure that we're clear on a couple of things. (If anything here is blindly obvious please forgive me, I don't intend to be insulting, I just want to make sure we're on the same page.)

First, client and server. Anything server-side runs under the context of a user account and is relative to the machine that it runs on. If you say "save this to the desktop" using server-side code, then this is the server's local process's desktop which almost never makes any sense. If you are impersonating the logged in user, however, this might work except that you are saving it to the logged in user's desktop on the server. If the client and the server are running on the same machine and you are impersonating the client then this might actually completely work. Maybe.

Second, Right-click, Save As. When you right-click a link you are invoking a browser's built-in proprietary menu system. That system is browser and/or OS-specific and is not defined in any specification out there. In the 90's you might have been able to use VBScript to "send keys" and have Internet Explorer "click" that link but those days are long gone. The closest modern equivalent to this would be to write a plugin which I imagine you don't want to do (and would be browser and/or OS-specific).

Third, MIME types. Generally speaking, every HTTP response includes a MIME type which specifies the server's intent for the bytes being sent. These include things like text/html and application/pdf. When server-side code (ASP.Net) doesn't get invoked, for instance static files like images and CSS or even pre-generated files like your PDF, the server (IIS) looks up the file extension in a list to determine what MIME type to send. On the client side the browser uses the MIME type to determine what action to take. If it is text/html it (probably) renders the HTML. If it is application/pdf then the browser looks at its list of MIME types to see if any application has that MIME type registered. Most modern browsers have a built-in PDF renderer so the browser just passes the bytes on to that to render. If the browser isn't aware of that MIME it might ask the OS if it knows about it and has a registered handler available and if so it passes that through. If that all fails (possibly because a user such as me has disabled that specific MIME type) then either the browser just puts those bytes into the "Downloads" folder, it tries to interpret those bytes as text or it prompts to save.

Going a little deeper into this last one, per the HTTP spec (19.5.1 paragraph 3), if you send a MIME type of application/octet-stream in addition to a header of Content-Disposition: attachment; filename="fname.ext" then

the implied suggestion is that the user agent should not display the response, but directly enter a `save response as...' dialog.

This is what you are ultimately trying to achieve, right?

In your case, clicking the PDF link bypasses ASP.Net and IIS just looks up the file and sends the application/pdf MIME type along with it. One fix is to de-register the PDF file extension from the system. This probably isn't the most portable solution, however. Similarly you could also just change the file extension to be application/octet-stream and you (might) get the Save As dialog.

What I would consider the best option for forcing the Save As dialog would be to create a handler of some sort server-side that forces the MIME type and Content Disposition headers into the stream and then passes the file's raw bytes. You could do this in a couple of ways, maybe with an IHttpHandler (maybe even better here) or possibly with just a single ASPX page that inspects the Query String. You'll want to perform some extra security and definitely make sure you don't allow path-like characters and commands in file names.

这篇关于如何从Sharepoint页面提示用户输入保存位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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