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); } } } } }
How could I make this if there are more attachment files?
regards
you can retrieve all the attachment and in your for each you could apply the same
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.
Hi , I hope we need to do some conversion for other type of file (.docx , .Excel ). Hope we need to do some more code stuff to achieve it
by the above code , by default where all these files are being saved , i am talking about the location
after retrieving how to display it in web form
how to read file with mime type ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document”
I need to read Excel file contents like rows and value of each cell
Any luck to read the excel file contents from CRM