Using Windows Azure Blob Storage with Dynamics CRM

In this article we are going to talk how Windows Azure Blob Storage can be used with Microsoft Dynamics CRM.

Business Scenario

In many of the CRM implementations, we come across requirement where certain documents are required to be linked with records such as accounts, contacts, cases, activities etc. For example –

  1. Insurance and Telco companies want to attached scanned copies of contracts, applications, health inspection reports, address/identity proof documents of the customers
  2. Public sector – store job orders, inspection reports, citizen document copies etc.

 In cases where these documents are large in number and size, we try to avoid out of box “Attachment” feature of the Dynamics CRM because it rapidly increases the CRM database size. We prefer using some document management solution such as SharePoint, Documentum and integrate with Dynamics CRM. In many cases, the document management solution comes as overhead because –

  1. The need is to just link documents with records – nothing more
  2. No workflow or search required
  3. Upfront large investment in DMS software as well as storage space
  4. Operational overhead in terms of backup and maintenance


The Windows Azure Blob Storage is an easy and economical option here. The following are merits of using blob storage in place of document management solution in such scenarios -

  1. Blob is storage focused only
  2. Provides storage redundancy – no need for back up, disaster recovery in place.
  3. Secure access provided. The storage data can also be encrypted
  4. No upfront investment – pay as you go (storage size) and it is very low-priced – check this out - <>

 What it takes to mingle both?

It is very easy to make both Dynamics CRM and Azure Blob Storage marry. There are well defined and documented APIs for the same. You can custom code integration as per need. I have built a small application ( web application) which can make this integration very simple. The application has a user interface as following –

With this application, you can do the following –

  • Create a container (folder) for each record using record identifier in Windows Azure Storage. Upload record specific documents in this folder.
  • You can upload, download, list and delete documents
  • Can upload any type of document and media
  • Enable role based access to upload, download, list and delete functions
  • Works with both Dynamics CRM on-premise and online

Installation and Configuration of Sample Application

I have attached code of the application in the article. Let me take you through steps to perform installation and configuration of the application.

1.       Create Windows Azure Storage Account – First step is to buy Windows Azure subscription and then create windows Azure Storage Account under your subscription. Please refer the following link - <>

 2.       If we try to understand Windows Azure Blob Storage structure in simple terms – A Windows Azure Storage Account can have multiple Containers. Each Container then can store multiple documents and media – each called one Blob. This application creates one container for each record then stores record specific documents and media in this container.

 3.       I assume you already have Dynamics CRM instance (online or on-premise) ready.

 4.       Download attached application ( web application) code and make changes to connection strings in web.config file –


<add name="blobstring" connectionString="DefaultEndpointsProtocol=https;AccountName=<STORAGE_NAME>;AccountKey=<ACCOUNT_KEY>"/>

 <add name="parentIdentifier" connectionString="<https://CRM_SERVER_NAME>;mainpage.aspx"/>



  • Replace <ACCOUNT_KEY> with primary key of the storage account (you can find in azure management portal)
  • Replace <https://CRM_SERVER_NAME> with Dynamics CRM Server name which we want to integrate. Note: This setting makes sure that you cannot invoke this application from any other place than from Dynamics CRM web site.  
  • Please replace <STORAGE_NAME> with storage account name created in step-1.


5.       Deploy the application

  • When using with Dynamics CRM online, please publish this application to Windows Azure Web Site. Refer this link - <>
  • For Dynamics CRM on-premise, you can publish this application to IIS server or to Windows Azure Web Site.


6.       Integrate with Dynamics CRM – These are two ways to integrate –

a.       Using IFRAME – The application has been designed to work by default with IFRAME. It can be configured at entity form level. When you configure the application for an entity, you can then link a document or media to entity record using azure blob as storage. Please perform the following steps for the configuration –


               i.      Open entity form for customization. It can be any entity such as account, contact, case, order etc.

               ii.      Insert IFRAME on the entity form.

               iii.      Set URL of the entity as https://<web_server_name>/mainpage.aspx . The <web_server_name> is the IIS server name or azure web site name where application has been hosted.

               iv.      Please be sure that you have checked “Pass record object-type and unique identifier as parameters” check box. It is very important to check this because with this setting the record GUID is passed in query string and application uses that to create unique container for the record in the azure storage. Without this setting, the application will not work.

               v.      Please also ensure to un-check “Restrict cross-frame scripting, where supported” check box. It is another important setting because otherwise application form will not post back and it will throw out into popup when posting back.   

               vi.      Finally save and publish the form customizations.

               vii.      You can now open entity record and link files to the record. Note: In case of new record, the application will not upload files unless the record has been saved. Remember it needs record GUID to create container for the record in the azure blob.

 b.      Using Ribbon Button – you can also configure the application with ribbon button but it needs some level of coding. I plan to create a ribbon in next version which will make integration easier. For now – please do the following –

               i.      Open entity form for customization.

               ii.      Create a ribbon button. Customize ribbon button to call a JavaScript function. The Java function should open the URL (https://<web_server_name>/mainpage.aspx?id=<GUID>) using Window. Open method. The <web_server_name> is the IIS server name or azure web site name where application has been hosted. The <GUID> is the GUID of the entity record.

               iii.      In the application, please open “mainpage.aspx.cs” file and remove the method “CheckReferalPage” and any reference to this method. Please compile and re-host the application.

 7.       Configure Role Based Access Control – I have not provided any role based access in the application but there are extensions available to easily configure the same. Please do the following –

 a.        When using with IFRAME –

               i.      Open entity form for customization.

               ii.      Create a JavaScript code on the “Form Load” event which passes user roles (Xrm.Page.context.getUserRoles()) in the hidden text box (id=iroles, name=txtroles) of the IFRAME page.

               iii.      In the application, please open “mainpage.aspx.cs” file and write role based access behaviour in private method “SetRoleBasedAccess”. Essential, you will read user role names passed and enable\disable control as per access provided to the role.

 b.      When using with Ribbon button - In ribbon button, implement the logic of JavaScript written above using HTTP POST methods.


This is a sample implementation to expedite basic integration of Windows Azure Blob with Dynamics CRM. I am sharing code with you; please feel free to make necessary changes in the code as required. Hope you like this article.