Azure Storage - 21: Azure Blob Service - Containers


In the previous post I have showed a couple basic PowerShell commands that are used to interact with Azure Blob Service. In this post I am going to show how to work with Azure Blob Service containers from code.


Refer to previous posts to get started with Azure Blob Service.


A container provides a grouping of a set of blobs. All blobs must be in a container. An account can contain an unlimited number of containers. A container can store an unlimited number of blobs. Note that the container name must be lowercase. Containers are created immediately beneath the storage account. It's not possible to nest one container beneath another.

There are two types of containers:

  • Root - a root container serves as a default container for your storage account. A storage account may have one root container. The root container must be explicitly created and must be named $root.
  • Other - all other named containers

The only difference between them is that a blob stored in the root container may be addressed without referencing the root container name, so that a blob can be addressed at the top level of the storage account hierarchy.

The following code creates a root container:

var rootContainer = blobClient.GetRootContainerReference();

To create a named container:

var container = blobClient.GetContainerReference("testcontainer");

I already covered how CreateIfNotExists, Create, DeleteIfExists and Delete commands work for tables at Part 12: Azure Table + .NET - Basics. This methods work in a similar way for containers. The only difference is that you need to specify BlobContainerPublicAccessType when you create a container. It can be:

  • Off - No public access. Only the account owner can read resources in this container.
  • Container - Container-level public access. Anonymous clients can read container and blob data.
  • Blob - Blob-level public access. Anonymous clients can read blob data within this container, but not container data

So you should use BlobContainerPublicAccessType.Blob for some static content that you want to share on your site.


In this post I have showed how to create the root container and a named container. In the next post I am going to show how to work with blobs inside a container.