Return to Snippet

Revision: 7967
at August 25, 2008 09:58 by Anthony


Updated Code
public static string SerializeBase64(object o)
{
    // Serialize to a base 64 string
    byte[] bytes;
    long length = 0;
    MemoryStream ws = new MemoryStream();
    BinaryFormatter sf = new BinaryFormatter();
    sf.Serialize(ws, o);
    length = ws.Length;
    bytes = ws.GetBuffer();
    string encodedData = bytes.Length + ":" + Convert.ToBase64String(bytes, 0, bytes.Length, Base64FormattingOptions.None);
    return encodedData;
}

Revision: 7966
at August 25, 2008 09:52 by Anthony


Initial Code
public static string SerializeBase64(object o)
        {
            // Serialize to a base 64 string
            byte[] bytes;
            long length = 0;
            MemoryStream ws = new MemoryStream();
            BinaryFormatter sf = new BinaryFormatter();
            sf.Serialize(ws, o);
            length = ws.Length;
            bytes = ws.GetBuffer();
            string encodedData = bytes.Length + ":" + Convert.ToBase64String(bytes, 0, bytes.Length, Base64FormattingOptions.None);
            return encodedData;
        }

Initial URL


Initial Description
Serializes an object to a Base64 string.  The first few characters of the serialized string indicate the byte length of the encoded data.

Initial Title
Serialize Object to a Base64 String

Initial Tags


Initial Language
C#