Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 2 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
My requirement was to register a plugin so that every time a file is attached to some entities, I download the file to a temp folder for performing some processing. Actually, in my case it was processing an Excel file as a more user-friendly data input for line items in opportunities and quotes, but that is anecdotic.
The 3 key points I would like to share here with you is how to:
Below are some parts of my plugin .cs file:
//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<Annotation>();
// RETRIEVE THE FILE CONTENT (DocumentBody property)
tempFile = SaveFile(note.FileName, note.DocumentBody);
// SAVE THE FILE
private static string SaveFile(string fileName, string noteBody)
string outputFileName = @"C:\temp\" + fileName;
// Download the attachment in the current execution folder.
byte fileContent = Convert.FromBase64String(noteBody);
throw new InvalidPluginExecutionException("File content is empty or cannot be retrieved");
Take note I’m using System.IO.File.WriteAllBytes. This is what did work for me. I’ve tried using WriteAllText and also FileStream but when trying to open the generated file, it was not in the right format.
Hope it helps,
PP [twitter: @pabloperalta]
Business Applications communities