What can I do to to store/save a list of Class on Windows Phone 8.1?

I have a small Project. I want to write a Windows Phone Application which stores a List of Items. I tried to save the list as a XML document using Linq, that worked fine on a PC but i got a problem with the

XDoc.Save();

On PC I could use a String but on Windows Phone I need a Stream or a XML(Text) Writer but I have no idea how I can do this. I tried to save a .txt file too, I always get the same exception and have no idea why.

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
        UnhandledException += (sender, e) =>
        {
            if (global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();
        };
#endif
        }
    }
}

If someone knows a way to store the List items. Please Help me.

Answers


To save to a file under Windows Phone 8.1 you have to use a StorageFile object. Here is an example:

      using System.IO;  // needed for OpenStreamForWriteAsync()
      ....

      StorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("myfile.xml", CreationCollisionOption.ReplaceExisting);
      using (Stream stream = await storageFile.OpenStreamForWriteAsync())
      {
          //try XDoc.Save(stream);
      }

to read a file:

        StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync(FILENAME);
        using (Stream stream = await storageFile.OpenStreamForReadAsync())
        {
            var XDoc = System.Xml.Linq.XDocument.Load(stream); 
        }

Need Your Help

Create multiple indexes on multiple properties in Neo4j

indexing neo4j

I have to create indices for around 15 different labels and 400 different properties. Currently I have a bash script that look like:

How to pass 2 arguments to jquery Find() method

javascript jquery jquery-selectors

I have created a table that displays data, when user click on Update button it turns table cells into input field where user can enter the data..