Create an Attachment in CRM using C#

Hi,

Here is the C# code for creating an attachment in CRM under an email.

  Entity attachment = new Entity(“activitymimeattachment”);
  attachment[“subject”] = “My Subject”;
  string fileName = “Sample.png”;
  attachment[“filename”] = fileName;
  byte[] byteArray= File.ReadAllBytes(@”CRM_Image.png”);
  attachment[“body”] = Convert.ToBase64String(byteArray);
  attachment[“mimetype”] = “text/plain”;
  attachment[“attachmentnumber”] = 1;
  attachment[“objectid”] = new EntityReference(“email”, new Guid(“8236E256-D50E-E511-80DB-C4346BAC476C”));
  attachment[“objecttypecode”] = “email”;
  objService.Create(attachment);
 

Hope this Helps


Happy CRM’ing
Gopinath

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 )

Google photo

You are commenting using your Google 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