15 Nov’16

Dynamics CRMAccessing Azure Blob storage from CRM Online Plugin

In this blog article, we will see how to access Azure Blob storage and create document in CRM by reading a specific blob document in Azure.


  1. Get the following details of the Azure Blob storage
    1. Primary access key
    2. Blob container name
    3. File Name of the document
  2. Now we will write a sample plugin code which will read document from the Azure Blob storage and create an Annotation in CRM.

Since we cannot use external DLL in CRM online plugins, we are going to use the Web request to access the Azure blob storage. The HTTP web request has a bunch of headers along the above details to successfully access Azure blob storage.

For this, I have used a RestHelper and BlobHelper utility code files, which have all the operations of (a) making a web request and (b) performing blob operations.

The Helper files and the CRM plugin sample can be found in the below GitHub link: GitHub: CRM Online Integration with Azure Blob

Using this we can get the document and create Annotation in CRM using the below code:

#region Connect and fetch the data from Blob storage

// Replace the below values with actual details from your Azure Blob storage
string storageAccount = "blobstorageaccountname";
string filename = "filenamehere"; // testdocument.pdf
string containerName = "containernameHere"; //documents
string storageKey = "primaryaccesskiyeofazureblobstorageaccount";

BlobHelper blobHelper = new BlobHelper(storageAccount, storageKey);
KeyValuePair<byte[], string> data = blobHelper.GetBlobResponse(containerName, filename);
byte[] body = data.Key;
string contentType = data.Value;

#region Create Annotation in CRM
string encodedData = System.Convert.ToBase64String(body);
Entity Annotation = new Entity("annotation");
Annotation.Attributes["objectid"] = new EntityReference(workOrder.LogicalName, workOrder.Id);
Annotation.Attributes["objecttypecode"] = workOrder.LogicalName;
Annotation.Attributes["subject"] = "Document from AX Integration";
Annotation.Attributes["documentbody"] = encodedData;
Annotation.Attributes["mimetype"] = contentType;
Annotation.Attributes["notetext"] = "REST API - Sample document from AX.";
Annotation.Attributes["filename"] = entity.GetAttributeValue<string>("cf_name");

Guid annotation = service.Create(Annotation);


Written by

Team Member


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Reading more then 10K records in D3FOE OData API

    11 July’ 2018

    Introduction: We all know Dynamics 365 Finance and Operations has limitation of 10K records to be fetched at a time usi...

    Read more
  • Paging in D365 Customer Engagement v9.0

    10 July’ 2018

    Introduction: The Xrm.retrieveMultipleRecords method is used to retrieve a collection of records in Dynamics 365 Custom...

    Read more
  • Set up Dynamics 365 connection in Microsoft Social Engagement

    10 July’ 2018

    Introduction: This blog explains how to Set up Dynamics 365 connection in Microsoft Social Engagement. Steps to be follo...

    Read more
  • Voice of the Customer failed to install

    10 July’ 2018

    Introduction: Many people face issues in installing Voice of Customer solution on v9 environment and trying repeatedly ...

    Read more
  • Scribe Insight AX as a Web Service Find Block issue

    10 July’ 2018

    Introduction: If we need to look up for any value from AX then we do it by using a Find Block in Scribe Insight Eg: Basi...

    Read more