Store PersistenceManager to IsolatedStorage

3 posts, 1 answers
  1. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 01 Feb 2012 Link to this post

    Hi,
    I used the GridViewCustomPropertyProvider sample which is nice thanks.

    The problem is to store those settings into IsolatedStorage...

    Is there an easy way I have missed?

    I had to create myself a function to copy the stream from one object to the other. I'm sure there is a way so obvious that you don't talk about anywhere ;)

    For people wondering, I'm calling the load in UserControl_Loaded and I save in various events like ColumnReordered, ColumnWidthChanged, Grouped, Filtered and Sorted.

    Thank you for your lights,
    John.

    private void Save()
            {
                // Obtain the isolated storage for an application.
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    //IsolatedStorageFileStream s = store.OpenFile(@"GridsCommand.txt", FileMode.Create, FileAccess.Write);
                    using (Stream stream = new IsolatedStorageFileStream(@"GridsCommand.txt", FileMode.Create, FileAccess.Write, store))
                    {
                        if (stream != null)
                        {
                            PersistenceManager manager = new PersistenceManager();
                            Stream str = manager.Save(this.grdBeneficiaire);
     
                            CopyStream(str, stream);
                        }
                    }
                }
            }
     
            public static void CopyStream(Stream input, Stream output)
            {
                byte[] buffer = new byte[8 * 1024];
                int len;
                while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    output.Write(buffer, 0, len);
                }
            }
     
            private void Load()
            {
                // Obtain the isolated storage for an application.
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (store.FileExists("GridsCommand.txt"))
                    {
                        using (Stream stream = new IsolatedStorageFileStream(@"GridsCommand.txt", FileMode.Open, FileAccess.Read, store))
                        {
                            if (stream != null)
                            {
                                PersistenceManager manager = new PersistenceManager();
                                manager.Load(this.grdBeneficiaire, stream);
                            }
                        }
                    }
                }
            }

  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Feb 2012 Link to this post

    Hi John,

    Indeed the PersistenceFramework allows you to persist the settings of the UIElements in an isolated storage out-of-the-box. As long as you set the telerik:PersistenceManager.StorageId attached property to the elements which settings you need to persist, you'll be able to use the PersistenceFramework IsolatedStorageProvider class to save and load the persisted data. You can find more info here.

    I also attached a sample project to demonstrate how to persist a RadGridView in an isolated storage. Let me know if it helps or if you need more info.

    All the best,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 06 Feb 2012 Link to this post

    Hi Tina,
    Thank you for the explanation.

    I saw the samples. It's just that they was a sample showinf isolatedstorage and a sample showing custom PersistenceManager, just no sample showing how to use both.

    Its very simple once someone tells you ;)

    Thanks you for the sample,
    John.

Back to Top