My case as said if for passing username and password along with if the user was a premium user and if when the app starts if they are already logged on. It would then re-log the user on automatically.
Here I create the storage in MainPage class
IsolatedStorageSettings myUserSettings = IsolatedStorageSettings.ApplicationSettings;
Here is the MainPage class method:
private void GetUserData()
{
// System.Diagnostics.Debug.WriteLine("Grabbing Data");
if (IsolatedStorageSettings.ApplicationSettings.Contains("userLoggedIn"))
{
string isLoggedIn = IsolatedStorageSettings.ApplicationSettings["userLoggedIn"] as string;
if (isLoggedIn.EndsWith("rue"))
isLoggedOn = true;
else
isLoggedOn = false;
// System.Diagnostics.Debug.WriteLine("log in data " + isLoggedIn + " " + isLoggedOn);
}
else
{
myUserSettings.Add("userLoggedIn", "false");
isLoggedOn = false;
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("fullAccess"))
{
string hasFullAccess = IsolatedStorageSettings.ApplicationSettings["fullAccess"] as string;
if (hasFullAccess.EndsWith("rue"))
fullAccess = true;
else
fullAccess = false;
}
else
{
myUserSettings.Add("fullAccess", "false");
fullAccess = false;
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("username"))
{
username = IsolatedStorageSettings.ApplicationSettings["username"] as string;
}
else
{
myUserSettings.Add("username", "");
username = "me";
}
if (IsolatedStorageSettings.ApplicationSettings.Contains("password"))
{
password = IsolatedStorageSettings.ApplicationSettings["password"] as string;
}
else
{
myUserSettings.Add("password", "");
password = "v";
}
myUserSettings.Save();
}
Now in my Login Class I have to create the storage variable again
IsolatedStorageSettings myUserSettings = IsolatedStorageSettings.ApplicationSettings;
And now once I verfied the user I write the relevant information to the storage file: (parts of method missing as irrelevant)
// Here I have just finished using JSON to extra info from a JSON response
if (success.EndsWith("rue"))
{
if (!myUserSettings.Contains("userLoggedIn"))
{
myUserSettings.Add("userLoggedIn", success);
}
else
{
myUserSettings["userLoggedIn"] = success;
}
if (!myUserSettings.Contains("username"))
{
myUserSettings.Add("username", username);
}
else
{
myUserSettings["username"] = username;
}
if (!myUserSettings.Contains("password"))
{
myUserSettings.Add("password", password);
}
else
{
myUserSettings["password"] = password;
}
if (!myUserSettings.Contains("fullAccess"))
{
myUserSettings.Add("fullAccess", fullAccess);
}
else
{
myUserSettings["fullAccess"] = fullAccess;
}
myUserSettings.Save();
and if something does not work, check that you did save the file as follows:
myUserSettings.Save();
Hope you can make sense of my example but please refer to the doco from Microsoft. This link shows a simple example I used to solve my requirements.