Under the ApplicationData type in the Windows namespace there are two types we need to look at. Let’s just get the facts straight, which you’d might already have guessed.
RoamingSettings are for saving app settings that will be synced across your Windows 8 devices. This is pretty cool given you sit at work, play WordRecon and suddenly your boss tells you to go home. You go hame and when you come home you open up your Surface and play the same game from where you left off.
LocalSettings is a bit more “local” since this is the place where you save settings that is only meant to be on the local machine. Secret stuff like the picture of the Michael Jackson statue you’ve wanted since last christmas.
Neither of these should be considered as a persistent datastore like your database. Like the type name indicates it’s for “settings”. You can of course “bend the rules” and start experimenting with the store.
How do you use these types ?
It’s very basic to use these to types, really:
public async Task SaveSomething(object data) {
await ApplicationData.Current.ClearAsync();
ApplicationData.Current.LocalSettings.Values["someobject"] = data;
ApplicationData.Current.RoamingSettings.Values["someobject"] = data;
}
public object GetSomething(string key) {
return ApplicationData.Current.LocalSettings.Values["someobject"];
}
Both setting files are located in your AppData folder, beneath the package ID of your app. E.g: C:\Users\USER\AppData\Local\Packages\PACKAGEID\Settings
Versioning of the data
App updates should not affect already saved data in the settings files. But!
There is one thing to be careful about. That’s versioning of the data you put into the store. You may discover that you’ve written some settings data and after an update of the app, the data is no longer to be found. This has to to with versioning of the files and your data.
If you fall into this akward and hard-to-test-for feature, make sure to add a version number for your data. Like so
await ApplicationData.Current.SetVersionAsync((uint)1, (setVersionRequest) => { });
That is given for both properitary settings and the files you save/create to the Local/Roaming folders as well.