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”;
Service.Create(Annotation);

Enjoy !!

Advertisements

Leave a comment

Filed under MS CRM 2011

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s