Tuesday, 18 November 2014

Container creation in Azure Storage

Every blob in the AzureStorage must reside in the Container.
Today i would like the simple way of creation of Containers from c#.Net, We can also create containers from Azure Management portal.

We need to configure Storage account connection String that i explained my earlier post

Configuring Azure Connection string using .Net Application

Next we need to add namespace declaration in the top of c# programming file, for accessing Azure Storage.

make sure we need to add reference the Microsoft.windowsAzure.Storage.dll

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
  


// Retrieve storage account from connection string.           
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse( 
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
              
 // Create the blob client.
  CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                

// Retrieve a reference to a container.
  CloudBlobContainer container = blobClient.GetContainerReference("MyPictures");

 // Create the container if it doesn't already exist.
 container.CreateIfNotExists();


By default containers are private in, we can also give the permissions for downloading the blobs.


No comments:

Post a Comment