Silverlight 4.0 FileStream

filestream, silverlight

Solution

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.

Problem

``` 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]

Original source