Windows Phone 7: FileStream exception

I try to use FileStream (using the System.IO namespace), but I get an exception:

Attempt to access the method failed 

Here is the code:

FileStream fs = new FileStream("file.txt", FileMode.Create); 

I searched on microsoft.com and I found that this error is due to the fact that I am using the wrong library link.

But in my project, I compile with mscorlib.dll from the folder: C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ Silverlight \ v4.0

I need some help, please.

+3
source share
2 answers

You will need to use IsolatedStorage , for example:

Place at the top of the file:

using System.IO.IsolatedStorage;

Then in your method do the following:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(istream))
        {
            sw.Write("Some Stuff");
        }
    }
}

: http://msdn.microsoft.com/en-us/library/cc265154(v=VS.95).aspx#Y300

, Windows Phone 7 IsolatedStorageExplorer

: http://msdn.microsoft.com/library/ff626516(v=VS.92).aspx

: http://create.msdn.com/en-us/education/documentation

+3

WindowsPhone IsolStorage - . , - http://3water.wordpress.com/2010/08/07/isolated-storage-on-wp7-ii/

:

    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    using (var readStream = new IsolatedStorageFileStream(fileName, FileMode.Open, store))
    using (var reader = new StreamReader(readStream))
    {
        return reader.ReadToEnd();
    }

:

    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    using (var writeStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store))
    using (var writer = new StreamWriter(writeStream))
    {
        writer.Write(content);
    }
+1

All Articles