Read Full Blog Post at below link ,

http://debugmode.net/2012/04/01/isolated-storage-helper-for-c-and-xaml-based-metro-application/


Why to Use

To work Structured Data in isolated storage. This will help to read, write and delete structured data in XAML based Windows 8 Metro Application.

Version : Windows 8 Consumer Preview


Background

I was working with storing and retrieving structured data in Isolated Storage. While Binging I came across nicely written http://winrtstoragehelper.codeplex.com/ by https://twitter.com/#!/jamiet Jamie Thomson.

This utility was written for Windows 8 Developer Preview . Some of the API got changed in Windows 8 Consumer Preview. I have modified those changes in the utility from http://winrtstoragehelper.codeplex.com/ and edited the classes to provide File name explicitly.

How to use ?

Download DLL and add to your project

you have a class Student

public class Student
    {
        public string Name { get; set; }
        public int RollNumber { get; set; }
    }


You want to save object of Student then you can save it in Local Folder of isolated storage as below


            Student objStudent = new Student { Name = "DJ ", RollNumber = 1 };
            var objectStorageHelper = new StorageHelper<Student>(StorageType.Local);            
            objectStorageHelper.SaveASync(objStudent,"abc");
        

And you can read back Student from isolated storage as below


public async void ReadData()
        {            
            var objectStorageHelper = new StorageHelper<Student>(StorageType.Local);           
            Student objStudent = await objectStorageHelper.LoadASync("abc");
            
        }


Abc is name of the file.

If you want to store List<Student> then you can do that as following,

List<Student> lstStudent = new List<Student>()
                                        {new Student { Name = "DJ ", RollNumber = 1 },
                                         new Student { Name = "debugmode", RollNumber = 2 }
                                        };

            var objectStorageHelper = new StorageHelper<List<Student>>(StorageType.Local);
            objectStorageHelper.SaveASync(lstStudent, "abc");
 

You can read List<Student> from local folder of isolated storage as following


public async void ReadData()
        {            
            var objectStorageHelper = new StorageHelper<List<Student>>(StorageType.Local);           
            List<Student> lstStudent = await objectStorageHelper.LoadASync("abc");
            foreach (var r in lstStudent)
            {
                string n = r.Name;
            }
        }


Here again name of the file is ABC.

Thanks
Dhananjay Kumar
http://debugmode.net/
https://twitter.com/#!/debug_mode

Last edited Apr 1, 2012 at 12:37 PM by debug_mode, version 3