Few months ago, I wrote a small helper class for all my Windows Phone Silverlight applications, which helped me a lot to store and retrieve data to and from IsolatedStorageSettings. Thus I thought to share the same with you, in case you find it useful.

 

Read more to  find out the code, which you can use freely. Here the only catch is: it works only with the Silverlight type applications.


 

 

The helper class consists of three methods named “StoreSetting”, “GetSetting” and “RemoveSetting”. As the name suggests, the said methods will help you to save, retrieve and delete your data to and from Isolated Storage Settings.

 

Please find below the complete source code which will work with Windows Phone Silverlight type applications, but I will try to provide another code snippet quite soon to help you work with Universal apps.

 

namespace KunalChowdhury.Helpers
{
    using System.IO.IsolatedStorage;
 
    public class StorageHelper
    {
        public static bool StoreSetting(string key, object value)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
            {
                IsolatedStorageSettings.ApplicationSettings[key] = value;
                return true;
            }
 
            IsolatedStorageSettings.ApplicationSettings.Add(key, value);
            return true;
        }
 
        public static T GetSetting<T>(string key, T defaultVal = default(T))
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
            {
                return (T)IsolatedStorageSettings.ApplicationSettings[key];
            }
 
            return defaultVal;
        }
 
        public static void RemoveSetting(string key)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
            {
                IsolatedStorageSettings.ApplicationSettings.Remove(key);
            }
        }
    }
}

 

I hope, this optimized code will help you to better utilize your data in Isolated Storage Settings. Don’t forget to check out my other Windows Phone related articles.

 

Connect with me over Twitter, Facebook and Google+. Subscribe to my blog’s RSS feed and Email Newsletter to get immediate updates about my posts in your inbox. Happy Coding. Cheers.

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.