How to use isolated storage API in Windows 8 Application

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.
 15:         Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always);
 17:         if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] == null)
 18:         {
 19:             Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
 20:         }
 21:     }
 22: }


Happy coding… 🙂

About Pavan Pareta

My name is Pavan Pareta, I enjoy computers and general technology. I am more interested in the areas of Computer Security, Programming and developing innovative s/w for Windows Mobile and Windows Phone 7. I like MS Technology and support open-source software, because I believe it plays a major role in knowledge sharing and exchange of ideas, which effectively leads to better software. Additionally, I am a follower of the KISS (Keep It Simple Stupid) philosophy. I Love C#.NET and recently I am fall in love with Silverlight :) Introduce to my machine My main workstation is a Intel Pentium Core Duo and my primary operating system is Windows 7.
This entry was posted in Isolated storage API, Windows 8. Bookmark the permalink.

5 Responses to How to use isolated storage API in Windows 8 Application

  1. Rakesh says:

    can you please help me in create a word doc in local storage and launching the same in windows phone 8.Any help would be appreciated.Thanks,Rakesh.

  2. Unknown says:

    BTW, none of these APIs are implemented on Windows Phone 8. They'll just throw NotImplementedExceptions.

  3. Pavan Pareta says:

    This API is only available for Windows 8 Application development. NOT for Windows Phone 8 Application development.

  4. ... says:

    That is a pity! It would be great to have a single storage solution for both Windows 8 and Windows Phone 8.I'm using the RoamingSettings in a Windows 8 app and hoped I could use the same in a Windows Phone 8 app to access the same data as the Windows 8 app.

  5. pushpen says:

    this is a good code to save data. but if i want to retrieve data than how can i do that ? please provide code for that too.

Leave a Reply

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

You are commenting using your 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