Hi,
I am trying to save data when the user click out of my app and i keep getting this erro:
System.InvalidOperationException was unhandled
Message=This operation would create an incorrectly structured document.
StackTrace:
here is the C# code that i am trying to run in my databound app in the App.xmal.cs page:
Can anyone tell me what is wrong and how to go about fixing it?
Thanks,
Nat
I am trying to save data when the user click out of my app and i keep getting this erro:
System.InvalidOperationException was unhandled
Message=This operation would create an incorrectly structured document.
StackTrace:
here is the C# code that i am trying to run in my databound app in the App.xmal.cs page:
Code:
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
var storage = IsolatedStorageFile.GetUserStoreForApplication();
if (storage.DirectoryExists("data") && storage.FileExists("data\\data.xml"))
{
storage.DeleteFile("data\\data.xml");
using (IsolatedStorageFileStream storageFile = new IsolatedStorageFileStream("data\\data.xml", FileMode.Create, storage))
{
XDocument xdoc = new XDocument(new XElement("Alarms"));
foreach (ItemViewModel alarm in App.ViewModel.Alarms)
{
xdoc.Add(
new XElement("Alarm",
new XAttribute("Name", alarm.Name),
new XAttribute("Playlist", alarm.Playlist),
new XAttribute("Time", alarm.Time.ToShortTimeString()),
new XAttribute("TimeString", alarm.TimeString),
new XAttribute("Active", alarm.Active.ToString())));
}
xdoc.Save(storageFile);
storageFile.Dispose();
storageFile.Close();
}
}
}
Thanks,
Nat