Azure DocumentDB – CRUD Operations

Started playing around with Azure DocumentDB, and I am pretty excited about it. The simplicity is just crazy. Most of the application out there need CRUD operations, So I thought I will try to compile them in 1 post for quick reference.

  • To begin with you need to create a DocumentDB database account. The below link walks through that.

  • Next step is to create DocumentDB collections, which will hold our documents.
  • Next step is to add documents into the collections. Following link explains how to add, view documents using the document explorer, we will look how to do them using the sdk.
  • Next step is to get the DocumentDB client library package to start coding against Azure DocumentDB.

  • Next create a DocumentClient , from which we will execute all our CRUD operations.

You can find the DocumentDB URI and primary key from the azure portal.


  •  Once we have a DocumentClient we are ready to work with collections. To work with collections we need to get the collection link, the easiest way to find the selflink for the collection is to use a tool called DocumentDB Studio .


Copy the selflink as part of your configuration.

As application developer we work with entities and objects and their json serialized formats, Azure DocumentDB is designed from the ground up to natively support JSON and JavaScript directly inside the database engine, which makes application development much more agile.  You can download the simple console application here which covers all the basic CRUD operations on Azure  DocumentDB. Also for quick reference, below is the code.

  •  Resources

Azure Storage Logging

You have configured azure storage to work with your application. Next step is to log all the requests that come to your azure storage. The steps are super easy. To Enable logging on your storage account.

  • Navigate to your azure storage account.
  • Click on the configure tab and find the logging section below.


  • Check all the requests you want to log, read/write/ delete on your Tables, Blobs and Queues.
  • Set the Retention policy in days, the number of days you want to keep the analytics data. Setting it 0 means no limit. It’s always good to set a retention period since logs can become large quite fast.
  • Once you enable logging, a blob container called $logs will be created in the same storage account(log files are saved as blobs)
  • I use a Azure Storage Explorer tool to see the contents of my log files.


  • You can also use azure storage client library to work with $logs blob container just like any other container. You can find all the code samples here .

Clone Git Repository using Visual Studio

How do you clone a Git repository using visual studio? Well it’s super easy. If you are using visual studio 2012 , then you should install Visual Studio Tools for Git .

Note: Visual Studio 2013 includes Git tools by default so these tools are not needed.

Following are the steps to Clone  Git Repository using Visual studio.

  • Navigate to Team Explorer -> Click on the plug icon to Connect to Team Projects .


  • You should be seeing a list of all Git Repositories. Click on Clone .


  •  Next step is to get the Clone Url from github. You can find the url on the right on the home page of every github project.


  • Paste the url.


  • Click on Clone to start cloning . Once the cloning is done, you can access the solution from Solution explorer.

Office365 API – Connected Services

I just started learning how to work with Office 365 APIs and I should say its pretty nice and the tooling support with visual studio makes it really simple to create connected apps that talk to your Office 365 mails, Sharepoint , OneDrive , contacts, calendars etc. To get started you first need a Office 365 subscription, once you get that you also get an azure subscription along with that which you can access using the same username and password in the url .

Once you login to your azure portal , you will see an Active Directory named after your organization.

Click on the name to see more details, here you will find many tabs including a tab called APPLICATIONS.  Click on Applications tab to see the apps which uses this AD.


  •  Registering Your App in Azure AD

Any app which has to talk to Office 365 using APIs has to be registered in Azure AD. Once you register your app it will appear in the application tab show above.

The easiest way to register your app is using the connected service feature of visual studio. Following are the steps to register your app using visual studio.


Sign in  using the tenant administrator and you should be able to see all the services you have access to(Calendar, Mail, Contacts ,Users etc.).


Go Ahead and click on each service and choose the permissions you want to give to your app.


Following is the list of all actions you can perform using Office 365 API.

What happens next when you click ok is the beautiful part, the tooling takes care of adding all the necessary nugget packages, it even shows you a webpage where you can get started with code samples.



For Everything related to Office365 API, Check out

For Code Samples do check out github

Azure webjobs with queue trigger

Most of the websites always require a batch processing job which can do resource intensive tasks like sending emails , listen to a queue etc. Azure Webjobs  allows us to just that and its just a .NET console application which runs within the context of an azure website.
These jobs can be scheduled to run on demand, continuously, or on a predefined schedule with a recurrence.
Additionally, operations defined within WebJobs can be triggered to run either when the job runs or when a new file is created in Blob storage or a message is sent to an Azure queue.
To create a azure webjob with queue trigger
1.Go to Visual Studio -> Right click your website -> Add -> New Azure Webjob project


2.Open Program.cs.
3.Modify the class Program so that it is public. If you do not make the class public, WebJobs will not detect and run your operations.
4.Inside Program.cs, add a using statement for Microsoft.Azure.WebJobs.
5.Inside main() you will see these 2 lines of code.
JobHost host = new JobHost();
which specifies that webjob will run continuously.
6.Next, add a method to be invoked by WebJobs, following method will invoked when a new message appears in the queue named myqueue.
public static void TriggerFunction([QueueTrigger(“myqueue”)]CloudQueueMessage message)


A webjob can also be triggered when a new blob is detected within the container.


To run this WebJob locally, you need to apply some local configuration. Open the App.config file and add connection strings for the canonical storage account connection strings expected by WebJobs SDK, AzureWebJobsDashboard, and AzureWebJobsStorage.

Be sure to replace name and key values with the values from your own storage account.

To test your webjob, set it as a startup project and press f5. Your webjob is up and running and waiting for a trigger, once a new message arrives in the queue the trigger function is trigerred.

Access Complete Result Set in a Content Search Webpart


While using the Display templates for Content Search Web part, we may need to access the whole result set at once. I faced a similar scenario where I needed the Results as whole and group them based on a Managed Property.

Normally if you open the out of the box Item Template you can see in a number of Places ctx.CurrentItem which gives you access to the current Item and all of its Properties.


As I Mentioned I wanted all the Results not just the Current Item, The below Single Line of code can give you access to that in JSON Format

var Results = ctx.ListData.ResultTables[0].ResultRows;

That’s it and you are good to go and on your way to create great search experience for the Users.

Create a SIngle page application- the easy way

I have been working with AngularJS since few months now, it would have been more if I not for John papa’s Hot Towel Nuget package.

The Nuget package saved so many hours of plumbing work and it works like a dream. I was able to create a Single page app within seconds. Sounds crazy . Not at all. Here’s how you do it.

  • Go to Visual Studio -> Create New Project.
  • Select ASP.NET Web Application. I Chose an Empty template.
  • createempty
  • click ok to create your web app.
  • Here comes the fun part.
  • Search for the following nuget package and install it on your solution.
  • addhtnuget
  • It will install all the required files.
  • installhtnuget
  • And That’s all. Press F5 to access your SPA.
  • spadone

Deploy Azure Website

There are quite a few ways to deploy your azure website using visual studio , but i find the following the easiest.

  • Create a vanilla website in azure. This is my destination site where I will deploy all my changes


  • Once you have created a website in azure, try accessing it from your browser.webcreated
  • You should see a welcome page similar to this.
  • accessweb
  • Next step is to make changes and deploy them to your website.
  • Let’s say you have to change the way your website looks like.
  • Create a new web application using visual studio.
  •  newweb
  • Once you have done your changes and ready to deploy to azure, navigate to
  • Find your web app and click on it to go to the dashboard page.
  • dashboard
  • Click on Download the Publish profile link to download the publishing profile file.
  • pubprofile
  • Move back to Visual Studio and right click on your web application and click on Publish.
  • vspublish1
  • You will find a dialog box like this. Click on Import.
  • importclick
  • Browse to the publish profile file you downloaded from azure and import the file. You should see all the details auto populate in the dialog box as shown below.
  • autopop
  • Click on publish to start the deployment process.
  • pubsuccess
  • Navigate to your website to see the changes deployed.
  • websuccess2
  • Continue this process for continuous deployment from visual studio.