从 Silverlight OutOfBrowser 应用程序访问特殊文件夹
在我的 Silverlight 4.0 应用程序(具有更高的信任级别)中,我尝试使用以下代码访问通用模板文件夹:
var folder = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
但是,此类代码会抛出 System.Security.SecurityException:
System.Security.SecurityException was unhandled by user code
Message=File operation not permitted. Access to path '' is denied.
StackTrace:
at System.IO.FileSecurityState.EnsureState()
at System.Environment.InternalGetFolderPath(SpecialFolder folder, SpecialFolderOption option, Boolean checkHost)
at System.Environment.GetFolderPath(SpecialFolder folder)
似乎访问除“我的文档”之外的任何文件夹当前用户会抛出这种异常 - 由于 SpecialFolder 枚举有更多值,它们有什么用?有什么方法可以验证此枚举/方法查找哪个文件夹,或者有任何其他方法来访问它?
Inside my Silverlight 4.0 application (with elevated trust level), I'm trying to access the common templates folder, using the code below:
var folder = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
However, such code throwsSystem.Security.SecurityException:
System.Security.SecurityException was unhandled by user code
Message=File operation not permitted. Access to path '' is denied.
StackTrace:
at System.IO.FileSecurityState.EnsureState()
at System.Environment.InternalGetFolderPath(SpecialFolder folder, SpecialFolderOption option, Boolean checkHost)
at System.Environment.GetFolderPath(SpecialFolder folder)
It seems that accessing any folder besides "My Documents" for the current user would throw this kind of exception - Since the SpecialFolder enum has more values, what are they good for? Is there any way to verify which folder this enum/method looks for, or any other way to access it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Silverlight 4 中,“我的文档”区域和独立存储是 OOB 应用程序可以任意读取/写入的唯一两个位置。 Silverlight 5 将改变这种情况,提高信任度的应用程序将能够更好地访问磁盘。
至于为什么它在那里,请参阅 MSDN 文档:
值得注意的是,如果您的目标是 Windows OOB,则可以使用 COM 自动化和
Scripting.FileSystemObject
在 Silverlight 4 中:In Silverlight 4, the "My Documents" area and isolated storage are the only two places that OOB apps my arbitrarily read/write from/to. This will change with Silverlight 5, where elevated trust apps will have greater access to disk.
As for why it's there at all, see the remark in the MSDN Documentation:
It's worth noting that if you are targeting windows OOB, it is possible to read/write files arbitrarily on disk using COM automation and
Scripting.FileSystemObject
in Silverlight 4: