简体   繁体   English

如何从Sharepoint页面提示用户输入保存位置?

[英]How can I prompt the user for a save location from a Sharepoint page?

I have a related question 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). 不幸的是,由于路径访问被拒绝(如上面链接中的Update 4中所述),该链接无法打开文件。

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"); 如果可能的话,我真正希望做的是提示用户输入保存位置(而不要求他们输入诸如“ 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. 不过,我不认为可以从Sharepoint页面上使用经过尝试但不太正确的FileSaveDialog(在这种情况下)。

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. 我认为这无法尝试保存客户端生成的文件,因为它是通过服务器端生成的(通过iTextSharp)。

UPDATE 2 更新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). 通过创建一个链接到文件(如我这样做,因为hown 这里 ),我可以右键单击链接说,选择“另存Taget为...”和这样做(“另存为”对话框出现,我可以将文件保存在我想要的任何位置)。 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)? 是否必须重新显示表单(创建“ show_sections()”函数并在保存按钮运行后调用它)?

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. 该系统是特定于浏览器和/或OS的,并且未在任何规范中定义。 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. 在90年代,您可能已经能够使用VBScript来“发送密钥”,并使Internet Explorer能够“单击”该链接,但是那些日子已经一去不复返了。 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 . 第三, MIME类型 Generally speaking, every HTTP response includes a MIME type which specifies the server's intent for the bytes being sent. 一般来说,每个HTTP响应都包含一个MIME类型,该类型指定服务器发送字节的意图。 These include things like text/html and application/pdf . 这些包括诸如text/htmlapplication/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. 如果未调用服务器端代码(ASP.Net),例如图像和CSS之类的静态文件,或者甚至是PDF之类的预生成文件,则服务器(IIS)会在列表中查找文件扩展名以确定什么要发送的MIME类型。 On the client side the browser uses the MIME type to determine what action to take. 在客户端,浏览器使用MIME类型来确定要执行的操作。 If it is text/html it (probably) renders the HTML. 如果是text/html则(可能)呈现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. 如果是application/pdf则浏览器将查看 MIME类型列表,以查看是否有任何应用程序注册了该MIME类型。 Most modern browsers have a built-in PDF renderer so the browser just passes the bytes on to that to render. 大多数现代浏览器都具有内置的PDF渲染器,因此浏览器只是将字节传递到该渲染器上。 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. 如果浏览器不知道该MIME,则可能会询问操作系统是否知道该MIME并具有可用的注册处理程序,如果可以,它将通过。 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. 如果所有操作都失败了(可能是因为像我这样的用户已禁用了该特定的MIME类型),那么浏览器要么只是将这些字节放入“下载”文件夹,它就会尝试将这些字节解释为文本,或者提示您保存。

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" 根据HTTP规范 (第19.5.1节第3节),如果您除了Content-Disposition: attachment; filename="fname.ext"的标头之外还发送MIME类型的application/octet-stream ,则对最后一个内容进行更深入的介绍Content-Disposition: attachment; filename="fname.ext" Content-Disposition: attachment; filename="fname.ext" then Content-Disposition: attachment; filename="fname.ext"然后

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. 在您的情况下,单击PDF链接会绕过ASP.Net,而IIS只会查找文件并发送application/pdf MIME类型。 One fix is to de-register the PDF file extension from the system . 一种解决方法是从系统注销PDF文件扩展名 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. 同样,您也可以将文件扩展名更改为application/octet-stream然后(可能)获得“另存为”对话框。

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. 我认为强制“另存为”对话框的最佳选择是在服务器端创建某种处理程序,该处理程序将MIME类型和Content Disposition标头强制放入流中,然后传递文件的原始字节。 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. 您可以通过两种方式来执行此操作,或者使用IHttpHandler在这里甚至更好),或者仅使用一个检查查询字符串的ASPX页面。 You'll want to perform some extra security and definitely make sure you don't allow path-like characters and commands in file names. 您将需要执行一些额外的安全性,并且绝对要确保在文件名中不允许使用类似路径的字符和命令。

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

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