While working on Windows 8 Application, I was under impression, is that we can use the Isolated storage API as it is like Windows Phone 7, but we can’t in Windows 8, Windows 8 introduce new API that is Windows.Storage. Storage API allows us to save data in Application level data. This is very simple and useful code snippet here.
1: public void SaveInfo(string key, string value)2: {3: if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
4: {5: if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key].ToString() != null)6: {7: // do update
8: Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
9: }10: }11: else
12: {13: // do create key and save value, first time only.
14:15: Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always);16:17: if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] == null)18: {19: Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
20: }21: }22: }
Cheer!!
Happy coding… :)
Post a Comment