Return to Snippet

Revision: 7969
at August 25, 2008 09:56 by Anthony


Updated Code
public static object DeserializeBase64(string s)
{
    // We need to know the exact length of the string - Base64 can sometimes pad us by a byte or two
    int p = s.IndexOf(':');
    int length = Convert.ToInt32(s.Substring(0, p));

    // Extract data from the base 64 string!
    byte[] memorydata = Convert.FromBase64String(s.Substring(p + 1));
    MemoryStream rs = new MemoryStream(memorydata, 0, length);
    BinaryFormatter sf = new BinaryFormatter();
    object o = sf.Deserialize(rs);
    return o;
}

Revision: 7968
at August 25, 2008 09:55 by Anthony


Initial Code
public static object DeserializeBase64(string s)
        {
            // We need to know the exact length of the string - Base64 can sometimes pad us by a byte or two
            int p = s.IndexOf(':');
            int length = Convert.ToInt32(s.Substring(0, p));

            // Extract data from the base 64 string!
            byte[] memorydata = Convert.FromBase64String(s.Substring(p + 1));
            MemoryStream rs = new MemoryStream(memorydata, 0, length);
            BinaryFormatter sf = new BinaryFormatter();
            object o = sf.Deserialize(rs);
            return o;
        }

Initial URL


Initial Description
De-serializes a Base64 String back to it's original object.  First x characters should indicate the byte length of the encoded data.

Initial Title
De-serialize Base64 String to Object

Initial Tags


Initial Language
C#