I wrote a program to pull all the attachment from a CRM 2013 instance. I think the code is typical:
/// <summary> /// Takes an attachment and writes out the document to an existing directory named for the objectid /// </summary> /// <param name="att">an activitymimeattachment</param> static void writeAttachment(Entity att) { if (att.Contains("body")) { string filepath = string.Format(@".\{0}\{1}", att.GetAttributeValue<EntityReference>("objectid").Id.ToString() , att.GetAttributeValue<string>("filename")); using (FileStream fs = new FileStream(filepath, FileMode.Create)) { byte[] attContent = new UTF8Encoding(true).GetBytes(att.GetAttributeValue<string>("body")); fs.Write(attContent, 0, attContent.Length); } } }
I was spot checking and discovered that any pdf I tried to open with Acrobat Reader came with the error message, "...could not open, ... because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."
I know that the way they got into CRM was by tracking the email via the Outlook client. Hence, the example caught my attention.
What gives?
many thanks,