How to get attachment content of post and comment in dynamics 365 using crm sdk

592 Views Asked by At

activityfileattachment and fileattachment entities, do have attachment information associated with the post but i am not able to find it's filecontent although activityfileattachment does have filecontent attribute but it has some GUID in it and there is no information on how to fetch attachment content using that GUID.

1)Here is documentation snap shot of that attribute filecontent of activityfileattachment (https://i.stack.imgur.com/hPl98.png)

2)This is that attachment object i am getting from activityfileattachment entity which has all details except attachment content which i want to download. (https://i.stack.imgur.com/SQXT2.png)

Please Let me know how can i get content of attachment using this GUID given in file content.

1

There are 1 best solutions below

0
ssedlacek On

attachments of Note/Post entity is actually stored in entity "ActivityMimeAttachment" (MS Documentation), so in order to get the attachment from note/post, so example query without using earlybound types could look similar to this:

public void SampleQuery(Guid postOrNoteId)
        {
            var query = new QueryExpression("activitymimeattachment")
            {
                Criteria = new FilterExpression()
                {
                    Conditions =
                    {
                        new ConditionExpression("objectid", ConditionOperator.Equal, postOrNoteId)
                    }
                }
            };

            var result = crmService.RetrieveMultiple(query).Entities.First();

            var fileContent = result.GetAttributeValue<string>("body");

            // Do your logic with filecontent .......
        }