简体   繁体   中英

WP8: Losing data or access to XML file in isolated storage

I am creating a WP8 shopping list app that stores user created lists(in my code, each shopping list is defined as a ListObj that I defined). I would like to save the lists created by users through an .xml file. As long as I continue to add to this list of ListObj's, I seem to have no issues. But I start to experience trouble when I want to remove a ListObj from my list. When I reopen my app after I removed something from my list of ListObj's and attempt to load my list upon start, I enter this try/catch block:

try
{
  using (IsolatedStorageFile appStorage =
           IsolatedStorageFile.GetUserStoreForApplication())
  {
    if (appStorage.FileExists("rootList.xml"))
    {
      using (IsolatedStorageFileStream isStream = 
               appStorage.OpenFile("rootList.xml", 
                                  FileMode.Open, FileAccess.Read))
      {
        XmlSerializer serializer = new XmlSerializer(typeof(List<ListObj>));
        rootList = (List<ListObj>)serializer.Deserialize(isStream);
      }
    }
    else
    {
      rootList = new List<ListObj>();
      Debug.WriteLine("rootList not found.");
    }
  }
}
catch
{
  ///Uhhh....
}

However, my program executes the catch statement in which nothing happens obviously. I am unsure of what to execute in this catch block in order to diagnose my problem. I think I am losing access to the app's Isolated storage but again, I am unsure as to how to proceed. Any ideas?

So I ended up finding a solution to my problem. It turns out that the way I modified my .xml file caused an error in which it can no longer be read. I solved this by completely overwriting my file with the modified data rather than trying to change the existing data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM