C# code to create a blob container if it doesnot exist

Rajnilari2015
Posted by Rajnilari2015 under Azure category on | Points: 40 | Views : 360
The below code will do so

public CloudBlobContainer GetCloudBlobContainer(string connectionString, string containerName)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobclient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobcontainer = blobclient.GetContainerReference(containerName);

if (blobcontainer.CreateIfNotExists())
{
blobcontainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
return blobcontainer;
}

Comments or Responses

Login to post response