web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Read a text file in 'notes'

(0) ShareShare
ReportReport
Posted on by 1,703

CRM 2016 On-Premises

I have a custom entity with a text file uploaded into each record 'notes' . 

I'm trying to grab the 'file' from annotation, open it and read it in a custom workflow with something like File Stream. I'd like to read the file directly from CRM rather than  write it to disc 

These text files are uploaded to CRM  and contain multiple data records that I need to process into different entities, hence the need to be be able to open each 'attachment' read and process it through a workflow.

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Pete N,

    You can obtain the contents of an annotation entity by using C#. This article explains how to achieve this.

  • Suggested answer
    Pete_N Profile Picture
    1,703 on at

    Thank you

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    FYI,

    //RETRIEVE THE NOTE
    
    protected void ExecutePostNoteCreate(LocalPluginContext localContext)
    
    {
    
        string tempFile = string.Empty;
    
     
    
        IPluginExecutionContext context = localContext.PluginExecutionContext;
    
        IOrganizationService organizationService = localContext.OrganizationService;         
    
        
    
        if (context.InputParameters.Contains("Target") &&
    
            context.InputParameters["Target"] is Entity)
    
        {
    
            Entity noteEntity = (Entity)context.InputParameters["Target"];
    
     
    
            Annotation note = noteEntity.ToEntity();
    
     
    
        .....
    
     
    
    // RETRIEVE THE FILE CONTENT (DocumentBody property)
    
    if (!string.IsNullOrEmpty(note.FileName))
    
    {
    
       tempFile = SaveFile(note.FileName, note.DocumentBody);
    
    }
    
     
    
    // SAVE THE FILE
    
    private static string SaveFile(string fileName, string noteBody)
    
    {
    
        string outputFileName = @"C:\temp\"   fileName;
    
     
    
        if (!string.IsNullOrEmpty(noteBody))
    
        {
    
            // Download the attachment in the current execution folder.
    
            byte[] fileContent = Convert.FromBase64String(noteBody);
    
            System.IO.File.WriteAllBytes(outputFileName, fileContent);
    
        }
    
        else
    
        {
    
            throw new InvalidPluginExecutionException("File content is empty or cannot be retrieved");
    
        }
    
     
    
        return outputFileName;
    
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans