Silverlight 4.0 FileStream

回眸只為那壹抹淺笑 提交于 2019-12-10 17:32:32

问题


FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

Arguments: << path >> Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.41108.0&File=mscorlib.dll&Key=FileSecurityState_OperationNotPermitted

The line of code above has an error [FileSecurityState_OperationNotPermitted]


回答1:


It sounds like your application is running in partial trust. To use a FileStream, you'll need to request elevated trust:

By default, Silverlight-based applications run in partial trust, which means they run within a security sandbox. Sandboxed applications have restricted access to the local computer and are constrained in other ways that help prevent malicious behavior.

From the Silverlight 4 FileStream documentation (emphasis mine):

When it is called by an elevated-trust application, exposes a Stream around a file, supporting both synchronous and asynchronous read and write operations.

EDIT: You can set an application to require elevated trust by setting the "Require elevated trust when running outside the browser" in your Silverlight project settings.



来源:https://stackoverflow.com/questions/2406216/silverlight-4-0-filestream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!