Sanket Ghorpade

Search–>Patterns—>Connect—->Innovate

Download Azure Storage files locally having files and directories – C# — March 2, 2019

Download Azure Storage files locally having files and directories – C#

Recently while implementing one feature for a product I encountered an issue of storing the Azure Blobs on my local machine.

What I wanted to achieve:
I wanted to iterate through the Blob storage which contains files and directories. The directories contain some files and I wanted to store all these files on my local machine with the same structure.
This is how my Azure Blob container structure is:

On AzureStorage Explorer this is how it looks

The issue was the directory which we see in Azure is not exactly a directory but is just a prefix to the blob file. So it was difficult to know which one is the directory as we will need that to create the same directory locally.

Solution:
After spending a few hours I realized we can fetch a BlockBlob and the directory by specifying the type of the blob. The following code seems simple once found but it took some time to figure out this is a possibility

This is the snapshot of the complete code. I have added comments that will help.

The complete solution can be found here: https://github.com/loflet/AzureBlobStorage
Feel free to comment on any issues or suggestion for this post.

Dhanyawad,
Sanket