在 Metrostyle 应用程序中读取 XML 文件?可能的?
我正在使用 Windows 8 开发者预览版。我希望开发一个读取 XML 文件的应用程序。是否可以?当我尝试使用 XDocument.Load(string uri) 时,它抛出了访问被拒绝异常,并且不存在诸如 FileStream 这样的类。我知道 Metro 风格应用程序基于 Silverlight,它无法访问文件系统,但它实际上是一个桌面应用程序,所以我不能读取文件吗?有什么解决方法吗?我对 silverlight 还很陌生,所以也许我只是不知道方法?
I'm using Windows 8 Developer Preview. I wish to develop an application that reads XML file. Is it possible? When I've tried to use XDocument.Load(string uri)
it threw an access denied exception and there's no such class as FileStream
. I know that metro style app are based on Silverlight which has no access to the file system, but it's actually a desktop app, so wouldn't I be able to read files? Is there any workaround? I'm pretty new to silverlight so maybe I just don't know the way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个 Metro 应用程序都是沙盒的。您需要指定从文档库或可移动存储读取文件的功能,并在包清单中关联特定类型。或者,您可以使用文件选择器,以便用户专门授予您对某些文件的访问权限。
引用自 访问用户使用 Windows 运行时的资源:
Every Metro application is sandboxed. You need to specify the capability to read files from Document library or from Removable storage, and associate specific types in your package manifest. Alternatively, you can use file picker, so that user specifically grants you access to some file.
Quote from Access to user resources using the Windows Runtime:
请阅读 Ari Polsky 在 MSDN 上对此问题的回答。
基本上,要访问文件,您需要获得许可。要获得该权限,用户必须使用提供的选择器之一选择其所在文件夹的文件来执行此操作。
另一种选择是声明您想要访问清单中的某个文件夹。但这仅适用于“图书馆”位置。
Read the answers by Ari Polsky to this question at MSDN.
Basically, to access a file, you need permission to do so. To get that permission, either the user has to do that by choosing that file of folder it's in using one of the provided pickers.
Another option is to declare that you want to access some folder in your manifest. But this works only for “Library” locations.