Saving Key-Value pair in Windows Phone using IsolatedStorageSettings

By | April 12, 2012

This sample code helps you to save a key and a corresponding value in windows Phone inside your application sandbox with the help of isolatedStorageSettings.

PLease check this post before working around this post.

How to save a text file in Windows Phone 7 or How to use isolated storage settings in Windows Phone 7?

Here is the C# code for this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;

namespace IsolatedStorageSettingsDemo
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;
            iss.Add("site", "coderzheaven.com");
            iss.Save();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;
            string data = "";

            try
            {
                iss.TryGetValue("site", out data);
                MessageBox.Show(data);
            }
            catch (Exception e1)
            {

            }
        }


    }
}

The stored value will be stored in a MessageBox.
Please leave your valuable comments on this post.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Reply

Your email address will not be published. Required fields are marked *