Create and attach text file to notes in Microsoft CRM 2011

If you have requirement to create and attach file to notes in Ms CRM 2011 using code then this post is for you, you can use below code

string strMessage=”this is a demo”;
byte[] filename = Encoding.ASCII.GetBytes(strMessage);
string encodedData = System.Convert.ToBase64String(filename);
Entity Annotation = new Entity(“annotation”);
Annotation.Attributes[“objectid”] = new EntityReference(“EntityName”,GUID);
Annotation.Attributes[“objecttypecode”] = “EntityNAME”;
Annotation.Attributes[“subject”] = “Demo”;
Annotation.Attributes[“documentbody”] = encodedData;
Annotation.Attributes[“mimetype”] = @”text/plain”;
Annotation.Attributes[“notetext”] = “Sample attachment.”;
Annotation.Attributes[“filename”] = “Demo.txt”;

Enjoy !!


Leave a comment

Filed under MS CRM 2011

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s