Archive
Adding file as “Attachment” to activities programmatically in plug-in
Hi,
We can add file as attachment and associate to the CRM objects i.e., Email, Task etc…
The entity that store attachment information is “activitymimeattachment”
Below is the code snippet to add “.pdf” file as attachment to the Email activity
Entity attachment = new Entity(“activitymimeattachment”);
attachment[“subject”] = “My Subject”;
string fileName = “Sample.pdf”;
attachment[“filename”] = fileName;
byte[] fileStream= = new byte[] { }; //Set file stream bytes
attachment[“body”] = Convert.ToBase64String(fileStream);
attachment[“mimetype”] = “text/plain”;
attachment[“attachmentnumber”] = 1;
Guid emailId; //GUID of Email activity
attachment[“objectid”] = new EntityReference(“email”, emailId);
attachment[“objecttypecode”] = “email”;
IOrganizationService service;
service.Create(attachment);
Note :-
- In the above code the property “objecttypecode” is slight misleading, as it expects “EntityLogicalName” rather than “EntityTypeCode”
- So make sure to set attachment[“objecttypecode”] = EntityLogicalName (i.e., email)
🙂
Stats
- 1,498,279 hits
Tweets
- RT @IFainberg: 🚀 THE TRACER: A new solution that uses #ProcessMining to understand usage patterns of #PowerApps at a massive scale. Get to… 3 weeks ago
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- Associate/Disassociate plugin messages in CRM
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- Azure DevOps (ADO) | Pipeline failure | You need the Git 'GenericContribute' permission
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- Azure DevOps (ADO) | Pipeline failure | Failed to connect to Dataverse
- Power Apps - 'Environment Variables' and their usage in Canvas Apps
- [Step by Step] Using TypeScript in Dynamics 365 9.x