Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Sample example regarding binary serialization in c sharp to save and retrieve the form's data.
Posted
Comments
OriginalGriff 16-Aug-11 4:31am    
Reason for my vote of one: Too lazy to use Google.
Smithers-Jones 16-Aug-11 7:14am    
Reasons for my vote of 1:
* Not a question (not even a full sentence)
* OP's request sounds demanding and like an order
* No effort
Conclusion: Lazy bum (TM).
Member 8150207 16-Aug-11 8:55am    
Sorry friends, i don't actually mean to ask in a rude way. I already have searched from google, and wrote code for serialization and deserialization, but the output is not coming from the last one week.I thought of asking to provide me some tutorial. Sorry once again.

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

MSDN[^]

CodeProject[^]

CodeProject again[^]

Start reading.
 
Share this answer
 
C#
public static string SerializeObject(object o)
    {
        if (!o.GetType().IsSerializable)
        {
            return null;
        }
        using (MemoryStream stream = new MemoryStream())
        {
            new BinaryFormatter().Serialize(stream, o);
            return Convert.ToBase64String(stream.ToArray());
        }
    }


C#
public static object DeserializeObject(string str)
{
        byte[] bytes = Convert.FromBase64String(str);
        using (MemoryStream stream = new MemoryStream(bytes))
        {
            return new BinaryFormatter().Deserialize(stream);
        }
}


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900