Dan
Dan

Reputation: 205

Writing entries from online XML file to isolated storage

I have a simple Silverlight WP7 app that reads the contents of an online XML file and displays them. However, there are maybe 150 items total and scrolling through them all can be quite inconvenient. So, I want make a sort of "Favorites" page. When you click on any item on the list, it writes it to a separate XML file within the app package. After it writes to that XML, I need to make sure it still updates the list each time the app is loaded, instead of strictly saving the contents of that entry at the time it was written. What method would be the best way to go about this?

Upvotes: 2

Views: 861

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1502376

First you get hold of the relevant IsolatedStorageFile using IsolateStorageFile.GetUserStoreForApplication() and then create a file using IsolatedStorageFile.CreateFile. That returns a Stream which you can write to in the normal way:

using (var storage = IsolateStorageFile.GetUserStoreForApplication())
using (var stream = storage.CreateFile("test.xml"))
{
    doc.Save(stream); // Where doc is an XDocument
}

It's as simple as that.

One key point is to avoid thinking of IsolatedStorageFile as a single file - think of it as being a whole drive for your application. It can contain files, directories etc. It may end up being a single file in the native file system, but your application doesn't need to know or care about that.

Upvotes: 5

Den
Den

Reputation: 16826

You could store the items to an XML file in the IsolatedStorage, just like you would do for any other file.

When the application is loaded, you need to set the actions in the Application_Launching event handler (in App.xaml.cs) - for example, you could create a List that will be bound to a ListView element that will get contain elements from the loaded XML file.

Upvotes: 1

Related Questions