Wednesday, 10 June 2015

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

No comments:

Post a Comment