This is a migrated thread and some comments may be shown as answers.

GridSettingsPersister saving to SQL.

4 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 2
Brad asked on 17 Dec 2012, 10:17 PM
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);
 
    
}

4 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 20 Dec 2012, 02:22 PM
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.
0
Brad
Top achievements
Rank 2
answered on 20 Dec 2012, 02:49 PM
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?
0
Accepted
Antonio Stoilkov
Telerik team
answered on 21 Dec 2012, 08:24 AM
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.
0
Brad
Top achievements
Rank 2
answered on 21 Dec 2012, 12:57 PM
Thank you for the sample code.  Your products are great.
Tags
Grid
Asked by
Brad
Top achievements
Rank 2
Answers by
Antonio Stoilkov
Telerik team
Brad
Top achievements
Rank 2
Share this question
or