mirrekhirren
mirrekhirren

Reputation: 21

how to save and load a object in a windows phone 7 app?

is it possible in a WP7 app to save some objects which i create and then load it when the app is started again?

Upvotes: 2

Views: 800

Answers (3)

Amr Angry
Amr Angry

Reputation: 3831

try after the example code above to add this. IsolatedStorageSettings.ApplicationSettings.save

Upvotes: 0

Subcreation
Subcreation

Reputation: 1353

Here's an example storing a string, but you should be able to store any type of object this way. Add IsolatedStorage to your references:

using System.IO.IsolatedStorage;

In your class:

private string myString;

In the Loaded event for your page:

try
{
    myString = (string)IsolatedStorageSettings.ApplicationSettings["myString"];
}
catch
{
    IsolatedStorageSettings.ApplicationSettings.Add("myString", "this value is a string");
}

and later, when you want to save:

IsolatedStorageSettings.ApplicationSettings["myString"] = myString;

Upvotes: 1

keyboardP
keyboardP

Reputation: 69362

You'll want to look to store persistent items into IsolatedStorage. You can see an overview and an example of how to use IsolatedStorage here. There are also a range of examples on this site, showing how to save different types of objects.

Upvotes: 2

Related Questions