views:

255

answers:

2

i have a person object and need to store it as byte[] and again retrieve that byte[] and convert to person object and BinaryFormatter is not availabe in silverlight

+1  A: 

Use the serialized class to convert the object into a byte via using a MemoryStream

using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

....
byte[] bPersonInfo = null;
using (MemoryStream mStream = new MemoryStream())
{
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new BinaryFormatter();
     bf.Serialize(mStream, personInfo);
     bPersonInfo = mStream.ToArray();
}
....
// Do what you have to do with bPersonInfo which is a byte Array...

// To Convert it back
PersonInfo pInfo = null;
using (MemoryStream mStream = new MemoryStream(bPersonInfo)){
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new BinaryFormatter();
     pInfo = (PersonInfo)bf.DeSerialize(mStream);
}
// Now pInfo is a PersonInfo object.

Hope this helps, Best regards, Tom.

tommieb75
Thanks Tom, The BinaryFormatter is not available in SilverLIght
taher chhabrawala
A: 

have u find any answer .i am also stuck on this .

Nitesh