Windows phone 7 不允许对IsolatedStorageFileStream执行操作

Windows phone 7 不允许对IsolatedStorageFileStream执行操作,windows-phone-7,windows-phone-7.1,windows-phone,windows-phone-7.1.1,Windows Phone 7,Windows Phone 7.1,Windows Phone,Windows Phone 7.1.1,创建文件后打开该文件时出错 using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication()) { myFileStore.CreateFile(DateTime.Now.Ticks + ".txt"); } using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())

创建文件后打开该文件时出错

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            myFileStore.CreateFile(DateTime.Now.Ticks + ".txt");
        }
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            temp = myFileStore.GetFileNames();
            for (int k = 0; k < temp.Length; k++)
            {
                IsolatedStorageFileStream file1 = myFileStore.OpenFile(temp[k], FileMode.Open, FileAccess.Read);
                dataSource.Add(new SampleData() { Name = temp[k], Size = Convert.ToString(Math.Round(Convert.ToDouble(file1.Length) / 1024 / 1024, 1) + " MB") });
            }
        }
使用(var myFileStore=IsolatedStorageFile.GetUserStoreForApplication())
{
myFileStore.CreateFile(DateTime.Now.Ticks+“.txt”);
}
使用(var myFileStore=IsolatedStorageFile.GetUserStoreForApplication())
{
temp=myFileStore.GetFileNames();
对于(int k=0;k
这是因为您没有关闭
CreateFile
方法返回的流

您的代码应该如下所示:

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
    myFileStore.CreateFile(DateTime.Now.Ticks + ".txt").Dispose();
}

在下面的OpenFile中也是如此

总之,您应该始终处理流(通过使用
using
子句或
dispose()
方法)

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication())
{
    using(myFileStore.CreateFile(DateTime.Now.Ticks + ".txt"))
    {
    }
}