How to Create a Blob Container in Azure Storage Account Programmatically using C#

Sathish Nadarajan
Solution Architect
July 27, 2017
Rate this article
[Total: 0    Average: 0/5]


On the Continuation of the Earlier Article, let us see how to create the Container using C# Programmatically.

1. As usual, let us create a Console application

2. Add the NuGet Packages

a. WindowsAzure.Storage

b. WindowsAzure.ConfigurationManager



3. Make a note of the Access keys.


4. We can use either the key1 or key2. It does not matter.

5. The below code snippet will create the Blob Container.

 using Microsoft.SharePoint.Client;
 using Microsoft.SharePoint.Client.RecordsRepository;
 using Microsoft.WindowsAzure.Storage;
 using Microsoft.WindowsAzure.Storage.Blob;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 namespace Office365.Console
     class Program
         static void Main(string[] args)
         public static void CreateContainer()
             string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=*************;AccountKey=**********;";
             // Parse the connection string and return a reference to the storage account.
             CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
             CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
             var containers = blobClient.ListContainers();
             // Retrieve a reference to a container.
             CloudBlobContainer container = blobClient.GetContainerReference("<<MyContainerName>>");
             container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container});

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment