Exporting serialized containers to file as binary?

I have been using the Textio & Comma classes to try and export records from a table (simple schema such as str,str,container). In SQL when I add a record to this table it saves the container as varbinary. However when I extract the records using one of the classes listed above it trys to serialize my container into a string and is messing up the format of my csv instead of getting “foo”,“bar”,“0x07FD300” I get “foo”,“bar”,“a”,“b”,d",“a” for example.

Does anyone know how to convert the container to binary so I can store it without messing up the schema of my csv file?

You could export binary data, nevertheless CSV is a text format, therefore you have to work with text (unless you switch to a binary file). Fortunately there is a way how to encode binary data to text - Base64 is the most common encoding. Call SysOperationHelper::base64encode() to do it in AX 2012.

Thank you very much.

If you’re satisfied with my answer, please mark it as Solution. It helps others to see that the problem is resolved and to find the answer if needed.