Hello,
I'm trying to fetch some data from the CRM, insert it into an excel sheet and attach it to an email.
I was able to retrieve the fetchxml data and convert it to DataTable. But I couldn't find a permitted way to convert the DataTable to Excel Sheet.
Here's my code so far:
Entity EmailAttachment = new Entity();
EmailAttachment.LogicalName = "activitymimeattachment";
EmailAttachment["objectid"] = new EntityReference("email", EmailId);
EmailAttachment["objecttypecode"] = "email";
EmailAttachment["subject"] = "Test Attachment";
string fetchxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='contact'>
<attribute name='fullname' />
<attribute name='telephone1' />
<attribute name='contactid' />
<order attribute='fullname' descending='false' />
<filter type='and'>
<condition attribute='fullname' operator='like' value='%Test%' />
</filter>
</entity>
</fetch>";
System.Data.DataTable resultTable = ExecuteFetchXml(fetchxml, service);
// how to convert resultTable to Excel file
EmailAttachment["body"] = // The Attachment should go here
EmailAttachment["filename"] = "TestAttachment.xlsx";
Guid attachmentId = service.Create(EmailAttachment);
*This post is locked for comments
I have the same question (0)