GridSettingsPersister saving to SQL.

5 posts, 1 answers
  1. Brad
    Brad avatar
    8 posts
    Member since:
    Oct 2011

    Posted 17 Dec 2012 Link to this post

    I am trying to save setting to SQL. It works fine until I recompile and then it falls apart.


    Does anyone have an example of the GridSettingsPersister that uses the BinaryFormatter instead of the LosFormatter?

    I am still unable to get the BinaryFormatter to work. Has anyone been able to get the GridSettingsPersister to work with the BinaryFormatter?

    public override string ToString()
    {
        //LosFormatter formatter = new LosFormatter();
        BinaryFormatter formatter = new BinaryFormatter();
     
     
        //using (StringWriter writer = new StringWriter())
        using (MemoryStream writer = new MemoryStream())
        {
            formatter.Serialize(writer, this);
            string arr = writer.ToString();
            return arr.ToString();
        }
    }
     
     
     
     
    /// <summary>
    /// Gets the GridSettingsCollectionInstance from its serialized string data
    /// </summary>
    /// <param name="data">The object as serialized string data</param>
    public static GridSettingsCollection LoadFromSerializedData(string data)
    {
       //LosFormatter formatter = new LosFormatter();
       BinaryFormatter formatter = new BinaryFormatter();
     
        
       byte[] arr = System.Text.Encoding.ASCII.GetBytes(data);
       MemoryStream stream = new MemoryStream(arr);
     
       //return (GridSettingsCollection)formatter.Deserialize(data);
       return (GridSettingsCollection)formatter.Deserialize(stream);
     
        
    }

  2. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 20 Dec 2012 Link to this post

    Hi Brad,

    The experienced behavior is expected. The BinaryFormatter will serialize a class differently every time the code is compiled because it generates different binary code. You could resolve your issue by using LosFormatter instead which generates string and could be saved in a database.

    All the best,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brad
    Brad avatar
    8 posts
    Member since:
    Oct 2011

    Posted 20 Dec 2012 Link to this post

    I was using the Losformatter but then every time I rebuild the project it can't read the old saved grid settings. Is there any work around?
  5. Answer
    Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 21 Dec 2012 Link to this post

    Hello Brad,

    I have assembled a sample project which saves the settings in the text file which is the as saving the data in the database. However, I was not able to replicate the problem. In order to further investigate the issue you could take a look at the attached project and modify it in order to show the unwanted behavior so we could be able to debug it and advise you with the best possible solution.

    All the best,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Brad
    Brad avatar
    8 posts
    Member since:
    Oct 2011

    Posted 21 Dec 2012 Link to this post

    Thank you for the sample code.  Your products are great.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017