Home > C#, Windows, Windows 8 > Windows 8 – How to save & retreive application settings

Windows 8 – How to save & retreive application settings

Windows 8 store applications don’t have application configuration files. Hence storing application level settings is done in a different way.

Each application has an ApplicationDataContainer. Its mutable and specific for each application. System internally manages the data by isolating it from other applications settings. Hence its more secure & reliable.

Current architecture offers 3 types of storage

  • Local – Here data is stored locally on the device
  • Roaming – Here data exists on all devices
  • Temporary – Temporary data

Here are two methods which you can use for saving and retrieving application data.


using Windows.Storage;

bool SaveSettings(string key, string value)
{
    try
    {
        var applicationData = Windows.Storage.ApplicationData.Current;
        applicationData.LocalSettings.Values[key] = value;
        return true;
    }
    catch
    {
        return false;
    }
}
string RetrieveSettings(string key)
{
    try
    {
        var applicationData = Windows.Storage.ApplicationData.Current;
        if (applicationData.LocalSettings.Values[key] != null)
            return applicationData.LocalSettings.Values[key].ToString();
        return null;
    }
    catch
    {
        return null;
    }
}

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 711 other followers

%d bloggers like this: