I’m using the following code to create and load the xml in the isolated storage. At the first part it creates the file in the isolated storage if it doesn’t exist, else it loads the already created/loaded in the isolated storage file.
The problem is when it tries to load the file it has (successfully) created/loaded in the first time the function was called. Here is the code
public void InitAch()
{
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.FileExists("Achievements.xml"))
{
using (Stream stream = storage.OpenFile("Achievements.xml", FileMode.Create, FileAccess.Write))
{
XDocument xml = XDocument.Load("Achievements.xml");
xml.Save(stream,SaveOptions.None);
}
}
else
{
using (Stream stream = storage.OpenFile("Achievements.xml", FileMode.Open, FileAccess.Read))
{
XDocument xml = XDocument.Load(stream,LoadOptions.None);
Lexis.Page4.Achievements.sheep = Int32.Parse(xml.Root.Element("BlackSheep").Value);
Lexis.Page4.Achievements.singularity = Int32.Parse(xml.Root.Element("Singularity").Value);
Lexis.Page4.Achievements.luke = Int32.Parse(xml.Root.Element("LuckyLuke").Value);
Lexis.Page4.Achievements.gardener = Int32.Parse(xml.Root.Element("Gardener").Value);
Lexis.Page4.Achievements.dumbo = Int32.Parse(xml.Root.Element("Dumbo").Value);
Lexis.Page4.Achievements.joker = Int32.Parse(xml.Root.Element("Joker").Value);
Lexis.Page4.Achievements.maid = Int32.Parse(xml.Root.Element("Maid").Value);
Lexis.Page4.Achievements.mr = Int32.Parse(xml.Root.Element("MrWords").Value);
Lexis.Page4.Achievements.secret = Int32.Parse(xml.Root.Element("Detective").Value);
}
}
}
I would appreciate your help.
In this code:
You’ll need to fix the creation of the XML file.