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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 182 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans