Hi All,
In this post i would like to explain how to retrieve annotation file and read the contents.
* First we need to retrieve annotation file using (Fetch / Querry expression / Querry by Attribute) Method.
* Get the Documentbody from annotation as Bytes and convert to String.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk; namespace RecruIT { public class ReadAnnotation : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); //retrieve annotation file QueryExpression Notes = new QueryExpression { EntityName = "annotation", ColumnSet = new ColumnSet("filename", "subject", "annotationid", "documentbody") }; Notes.Criteria.AddCondition("filename", ConditionOperator.Equal, "MS CRM 2011.txt"); EntityCollection NotesRetrieve = service.RetrieveMultiple(Notes); if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0) { { //converting document body content to bytes byte[] fil = Convert.FromBase64String(NotesRetrieve.Entities[0].Attributes["documentbody"].ToString()); //Converting to String string content = System.Text.Encoding.UTF8.GetString(fil); } } } } }