BinaryFormatter to string

Hi

I currently have a BinaryFormatter that serializes player levels and all that stuff. But I also need to be able to upload these levels to a webserver and the webserver can only take strings for data storage. So I can make the deserialized info into a string?

The level file is called by using FileStream. It finds the file at a location and serializes/deserializes it. It then gets all the variables I’ve set in a class and then assign the needed variables with the right data from the deserialized class.

I am not sure of what code I will show since it is pretty basic but if you want to know how I did the serialization, then go here. It starts around 30-31 minutes in.

Thanks in advance!

EDIT: I realized it was bit short on information so I added a bit more.

Here’s how I’m doing it. You can probably apply this to your situation.

private static string SerializeDataToString(OptionsData staticOptions)
{
    MemoryStream ms = new MemoryStream();
    XmlSerializer xs = new XmlSerializer(typeof(OptionsData));
    XmlTextWriter tw = new XmlTextWriter(ms, Encoding.UTF8);
    xs.Serialize(tw, staticOptions);
    ms = (MemoryStream)tw.BaseStream;

    string xmlizedString = UtfToString(ms.ToArray());
    return xmlizedString; 
}

private static string UtfToString(byte[] bytes)
{
    UTF8Encoding encoding = new UTF8Encoding();
    string constructedString = encoding.GetString(bytes);
    return (constructedString);
}