TIP
💡 Learn more : Azure storage account overview (opens new window).
# Creating an Azure Blob Hierarchy
We've reviewed the following options with Azure Storage so far:
- Working with Azure Storage Blobs and Files through the Portal (opens new window)
- Create an Azure Storage Blob Container through C# (opens new window)
- Uploading and Downloading a Stream into an Azure Storage Blob (opens new window)
- Working with Azure Storage Explorer (opens new window)
- Copy Azure Storage Blobs and Files via C# (opens new window)
Today, we are going to look at creating an Azure blob hierarchy via C#. Go ahead and open the Azure Portal and open the C# app that we worked with earlier (opens new window). If you want to start from this post, then use the code located here (opens new window).
The goal of this exercise is to create a blob hierarchy or folder structure inside of our container. So for example, we'd like to place a file in a structure such as backup/images-backup.png.
If you look below, you will notice that there is no way to create a folder structure from inside the portal.

But we can easily do this with code by adding the folder structure we want into the code as shown below.
static void Main(string[] args)
{
BlobServiceClient storageAccount = new BlobServiceClient(CloudConfigurationManager.GetSetting("StorageConnection"));
BlobContainerClient container = storageAccount.GetBlobContainerClient("images-backup");
container.CreateIfNotExists(PublicAccessType.Blob);
// line modified
BlockBlobClient blockBlob = container.GetBlockBlobClient("backup/mikepic.png");
using (var fileStream = System.IO.File.OpenRead(@"c:\mikepic.png"))
{
blockBlob.Upload(fileStream);
}
// line modified
Console.ReadLine();
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
If we run the application and switch over to our Storage Account and navigate inside the container, we'll see our container now has a folder:
