如何在 Silverlight 中本地保存多个文件?
我的问题是我有一个 LOB 应用程序,它可能可以根据用户输入保存多个文件(仅在运行时知道的文件数量)。不幸的是,将其保存为单个文件并让用户将它们分开,或将它们压缩为单个文件并不是一个选择。
SaveFileDialog 似乎适合一次仅保存 1 个文件。第三方控件可能是一种选择,但我还没有找到任何可以达到此目的的控件。谢谢!
My problem is I have a LOB application that can possibly save multiple files (number of files only known at runtime) based on user inputs. Saving this as a single file and having the user break them apart, or zipping them up as a single file is not an option unfortunately.
SaveFileDialog seems suited to only save 1 file at a time. Third party controls may be an option but I have yet to find any that serve this purpose. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器安全模型指南(Silverlight 之外)禁止 Web 应用程序逻辑(脚本或其他)直接访问本地文件系统。
考虑一下,如果 Web 应用程序脚本可以将任意文件写入本地硬盘上的任意位置,恶意网站可能会对您的计算机造成多大的破坏!
因此,Silverlight 将您的代码与本地文件系统隔离。 Silverlight 管理“打开文件”或“保存文件”对话框,但出于安全原因,您的 Web 应用程序代码永远无法直接查看文件名的完整路径。 Silverlight 对话框一次仅支持使用一个文件名/路径。
Silverlight 确实在本地计算机上提供了独立存储,您的 Web 应用程序可以在其中写入多个文件。然而,正如评论中所指出的,隔离存储是双向隔离的 - 它使 Web 应用程序与本地文件系统隔离,这使得最终用户很难在浏览器之外访问隔离存储的内容。 (对于非技术用户而言困难到无法使用,但还不足以将隔离存储称为“安全”的恶意窥探)。
如果没有编写您自己的本机可执行浏览器扩展(对于您希望支持的每个不同的浏览器品牌和版本)(或针对某些浏览器的非沙盒 JavaScript 插件),我认为 Web 应用程序没有办法推送数据转换为多个本地文件,方便在一次用户操作中在浏览器外部使用。
The browser security model guidelines (outside of Silverlight) prohibit web application logic (script or otherwise) from having direct access to the local file system.
Consider what havoc a malicious web site could wreak on your computer if web application script could write arbitrary files to arbitrary locations on the local hard disk!
For this reason, Silverlight isolates your code away from the local file system. Silverlight manages the Open File or Save File dialogs, but your web app code never gets to see the full path of the file names directly for security reasons. The Silverlight dialog only supports working with one filename / path at a time.
Silverlight does offer isolated storage on the local machine in which your web app could write multiple files. However, as noted in comments, isolated storage is isolated in both directions - it keeps the web app isolated from the local file system, and that makes it difficult for the end user to access the contents of the isolated storage outside of the browser. (Difficult enough to make it infeasible for nontechnical users, but not difficult enough to call isolated storage "secure" from malicious snooping).
Short of writing your own native executable browser extension (for each different browser brand and version you wish to support) (or non-sandboxed javascript plugin for some browsers), I don't think there is a way for a web app to push data into multiple local files convenient to use outside of the browser in one user action.
由于这是 Intranet 区域中的 LOB,您是否考虑过要求您的用户以 OOB 身份安装该应用程序并提高信任度。这将允许您将文件写入用户的文档文件夹,而无需使用 SaveFileDialog。
另一种选择是使用单个 SaveFileDialog 调用来压缩文件。
没有其他面向 Silverlight 的解决方案。
Since this is an LOB in the intranet zone have you considered asking your users to install the app as OOB with Elevated trust. This would allow you to write files to the users Documents folder without the SaveFileDialog.
The other option is to zip the files with a single SaveFileDialog call.
There are no other Silverlight oriented solution.