Windows 8 - Save and retrieve application settings
Windows Store apps have no config file. Use ApplicationData.Current.LocalSettings to save and read app settings in C#.
Windows 8 Store apps have no application configuration file, so settings are stored differently. Each app gets its own ApplicationDataContainer. The system isolates it from other apps, which keeps it secure and reliable.
There are three kinds of storage:
- Local - data is stored on the device.
- Roaming - data follows the user across devices.
- Temporary - data the system may clear.
These two methods save and read a value from the local settings.
csharp
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;
}
}
Example
csharp
SaveSettings("UserName", "amal");
string name = RetrieveSettings("UserName"); // "amal"