Using CDO to Encode Binary Files

I have found myself in several situations where I have needed to take a binary file and encode it for some sort of data transmission (over HTTP, XML, WebDAV, EDI, etc).

ITPro Today

February 18, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today

I have found myself in several situations where I have needed to take a binary file and encode it for some sort of data transmission (over HTTP, XML, WebDAV, EDI, etc).

While having an encoder COM component is nice, its can be expensive to find one that utilizes all "standard" modes of encoding (UUENCODE, BASE64, 7 Bit, 8 Bit, etc)

Well, a cheap way to do this is using the CDO.Message interface with ADO.

Since CDO is based on Internet internet standards (SMTP, MIME, etc), it utilizes all the "standard" methods for encoding messages and attachments for mail delivery.

To encode a file, all you need is to create an instance of a Message. Attach a file to that message. Then set an ADO stream to the bodypart of your message. Finally you can read the "encoded" string for your message right from the ADO stream object.

To unencode it, all you need to do is reverse the method described above.

You can simply change the "encoding" method by changing the Now, this may not be the most efficient method for data encoding and this method has not been tested for scalablity. But if you need a cheap quick and dirty method for binary encoding, CDO is the best method I have found.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like