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);
 }
 }
 }
 }
}

Read Annotation

:)

Advertisements

4 thoughts on “Read Annotation File Contents CRM 2011 c#

  1. With the given code i’m only able to read text. file data , Is there any way to read the Content of word file attached to Email record.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s