Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Programmatically attaching file to Note - CRM 4.0

Post Author: Joe D365 |

In Dynamics CRM 4.0, file attachment to entities is pretty simple as compared to CRM 3.0. UploadFromBase64DataAnnotationRequest and UploadFromBase64DataAnnotationResponse object are both deprecated. Instead a new attribute has been introduces in annotation object with documentbody that accepts string in base64 encoding. Please find the below sample:

Reading file data into Byte array and then converting it to base64. Since I am using in memory object of StringBuilder class so I have just used str.ToString() to return string.

Byte[] data;
ASCIIEncoding encode = new ASCIIEncoding();
data = encode.GetBytes(str.ToString());
string b64 = Convert.ToBase64String(data);

Next, simply create the annotation entity and set the attributes as below:

annotation note = new annotation();

note.subject = "Test Export";
note.filename = "exported.txt";
note.mimetype = "text/html";
note.documentbody = b64;
note.objectid = new Lookup();
note.objectid.type = "new_export";
note.objectid.Value = entityid;
note.objecttypecode = new EntityNameReference();
note.objecttypecode.Value = "new_export";

Guid annotationId = service.Create(note);

 

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

PowerObjects Recommends