Lenny
Lenny

Reputation: 343

Decoding MailMergeTemplate "Body" in Microsoft Dynamics CRM

Microsoft Dynamics CRM uses mail merge document templates in the Word XML format (i.e. the files are an XML string).

However, Microsoft Dynamics CRM stores these files as encoded strings rather than XML, an example follows:

"77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiI..."

Is there a way to decode the file body for a Mail Merge Template in Microsoft Dynamics CRM 2013 using the Microsoft.Xrm.Sdk and C#?

Upvotes: 1

Views: 600

Answers (1)

Zach Mast
Zach Mast

Reputation: 1718

I am not 100% certain but template body text is probably stored in UTF8 format similar to web resource content. Give the following conversion a try:

//Loading
byte[] binary = Convert.FromBase64String(mailMergeTemplate.Attributes["body"].ToString());
string bodyContent = UnicodeEncoding.UTF8.GetString(binary);

//Storing
byte[] bytes = UnicodeEncoding.UTF8.GetBytes(bodyContent);
mailMergeTemplate.Attributes["body"] = Convert.ToBase64String(bytes);

Upvotes: 2

Related Questions