Windows Phone 7 : FileStream exception

后端 未结 2 1368
花落未央
花落未央 2021-01-14 18:03

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

Attempt to access the method failed 

Here is the code :

<
2条回答
  •  粉色の甜心
    2021-01-14 18:16

    On WindowsPhone you must use IsolatedStorage - see this tutorial for example - http://3water.wordpress.com/2010/08/07/isolated-storage-on-wp7-ii/

    Read:

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

    Write:

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

提交回复
热议问题