0

我想写一个字符串的IsolatedStorageFile,但我得到一个IsolatedStorageException,在异常的链接,这是一个:定义未发现时,试图写入IsolatedStorageFile

http://www.microsoft.com/getsilverlight/DllResourceIDs/Default.aspx?Version=4.0.50829.0&File=mscorlib.dll&Key=IsolatedStorage_Operation_ISFS 

它声明无法找到'resource ID'的定义。我不知道为什么会发生这种异常,这里是我的代码:

private void writeListToStorage(List<PlanningItemModel> items) 
    { 
     IsolatedStorageFile myIsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication(); 
     if(myIsolatedStorageFile.FileExists("Zomerparkfeesten\\" + filePath)) 
     { 
      IsolatedStorageFileStream iStream = myIsolatedStorageFile.OpenFile("Zomerparkfeesten\\" + filePath, FileMode.Open, FileAccess.Write); 
      string json = Converter.convertListOfItemsToJson(items); 
      StreamWriter writeFile = new StreamWriter(iStream); 
      try 
      { 
       writeFile.WriteLine(json); 
       writeFile.Close(); 
       iStream.Close(); 
      } 
      catch (IOException) 
      { 
       writeFile.Close(); 
       iStream.Close(); 
      } 
     } 
     else 
     { 
      myIsolatedStorageFile.CreateFile("Zomerparkfeesten\\" + filePath); 
      this.writeListToStorage(items); 
     } 
    } 

任何想法?

+0

你有文件夹创建Zomerparkfeesten?它在哪一行中断? –

+0

是的,只要我尝试在myIsolatedStorageFile上执行操作,该文件夹就会中断。我试过OpenFile和DeletFile,它每次都抛出异常。 –

+0

您是否尝试过以下语法:http://stackoverflow.com/questions/12625910/getting-operation-not-permitted-on-isolatedstoragefilestream-saving-jpg(var stream = new IsolatedStorageFileStream(“folder \\”+ fileName,FileMode .Create,FileAccess.Write,myIsolatedStorage)) –

回答

1

它指出,“资源ID”的定义无法找到

不,这不是它说什么。奇怪的问题,可能与你说荷兰语而不是英语有关。看起来他们摸不着这个特殊例外的荷兰本土化。当我访问该网址来自美国,我得到:

不允许操作上IsolatedStorageFileStream

这当然使得很多更有意义,给出的代码片段。除此之外,我无法为您提供更多帮助,基本问题是您的程序无法访问隔离存储。你需要给它访问权限。

一个很难诊断的令人讨厌的失败模式,当您为“filePath”传递一个空字符串时,此代码将始终与“操作不允许”一起炸毁。这将使代码尝试写入与现有目录具有相同名称的文件,这是永远不允许的。

+0

感谢您回答这个问题!你知道是否有任何方法可以到达英文版的链接?禁用本地化,像我得到的那样的错误在未来不会有太大的帮助。感谢您的明确答案! –

+0

http://www.wikihow.com/Change-Your-Browser%27s-Language –

+0

这没有奏效,我试过安装Hola扩展等软件,但它也没有改变错误信息。 –

0

尝试使用此代码:

using (IsolatedStorageFile myIsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       if (!myIsolatedStorageFile.DirectoryExists("Zomerparkfeesten")) 
       { 
        myIsolatedStorageFile.CreateDirectory("Zomerparkfeesten"); 
        myIsolatedStorageFile.CreateFile("Zomerparkfeesten//" + filePath); 

       } 
       else 
       { 
        if (!myIsolatedStorageFile.FileExists("Zomerparkfeesten//" + filePath)) 
        { 
         myIsolatedStorageFile.CreateFile("Zomerparkfeesten//" + filePath); 
        } 

       } 

       using (Stream stream = new IsolatedStorageFileStream("Zomerparkfeesten//" + filePath, FileMode.Append, FileAccess.Write, myIsolatedStorageFile)) 
       { 
        using (StreamWriter writer = new StreamWriter(stream)) 
        { 
         writer.WriteLine("Test");// some your data 
         writer.Close(); 
         stream.Close(); 
        } 
       } 

      } 
相关问题