You need to sign in to do that
Don't have an account?
gsickal
Encoding/Decoding Word documents the Office Toolkit and Base64
I have wrritten an addin using the Office Tookit that takes a Word document and saves it as an Attachment in the salesforce system. The problem is, when I set the body field as the Word document, it isn't encoded in Base64 (the API docs say the client app is responsible for encoding and decoding the binary attachments as Base64 when sending or receiving objects including Attachments, MailMerge templates, and S-Controls.
I have googled and searched the Microsoft and MSDN pages and haven't found anything yet. Does anyone know of any converter or have any VBA code that will decode/encode a Word document back and forth between Base64? Thanks
http://www.motobit.com/tips/detpg_Base64Encode/
I would have thought it worked too, since using the regular API the SOAP layer takes care of this for you. But... when I tried it from code, i.e.
'// create a new attachment
Dim oAttachment As SObject3
Set oAttachment = oSession.CreateObject("Attachment")
'// set attachment properties from some values in the document
oAttachment("ParentId") = parentId
oAttachment("OwnerId") = ownerId
oAttachment("Name") = ActiveDocument.Name
'// we're responsible for Base64 encoding/decoding
oAttachment("Body") = ActiveDocument
'// save the attachment to salesforce
oAttachment.Create
The attachment got saved to salesforce fine, but when I tried to view it, it was garbage. After re-reading the API docs for the Toolkit, I came across this last bullet point in the section near the front of the manual called "Comparing the Office Toolkit and the Web Services API":
Well, there you have it. Now I had to figure out a way to encode the Word document to base 64 (it works automatically via SOAP when you attach a normal attachment through the salesforce ui, just not through the office toolkit), and decode it back when I retrieved attachments. Anyway, it's gotten a little more complicated now because I have to create a COM object in C++ that does the actual base64 encoding/decoding that I can call from with VBA for Word...
If you have already found a solution to this, I found this one:
http://download.paipai.net/texts/midCrypt.htm
It is designed for use in ASP(.NET) but should also work in VBA.
Warren Lester
Old thread, but you guys helped me out (and I've gotten lots of help from Ron Hess over the years) so here's something that may help others. I stumbled across what seems to be an elegant and quick solution:
http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp
He uses MS XML and an XML DOM document to convert from a byte array to Base64. We were already using MS XML in our app so this fit well. Still in initial testing but so far works well and seems pretty fast (haven't done detailed timing but the entire process to create the array, convert it and upload to an Opp Attachment is about 4 sec for a 150 KB PDF, and my machine isn't real fast).
He also has a simple proc to populate the byte array needed for conversion:
http://www.nonhostile.com/howto-read-write-byte-arrays-files-vb6.asp
I literally pasted both these into my VBA (Access) code with no changes and they work perfectly for PDF, Word, and Excel so far.
Good luck to all!