Download File from container that has recursive directories and files


  • Hi Team,

    I used below code snipet to download files from blob storage.

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(

    // Create the blob client.
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    // Retrieve reference to a previously created container.
    CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

    // Retrieve reference to a blob named "photo1.jpg".
    CloudBlockBlob blockBlob = container.GetBlockBlobReference("photo1.jpg");

    // Save blob contents to a file.
    using (var fileStream = System.IO.File.OpenWrite(@"path\myfile"))

                    foreach (IListBlobItem item in container.ListBlobs(null, false))

                       if (item.GetType() == typeof(CloudBlockBlob))
                            CloudBlockBlob blob = (CloudBlockBlob)item;

                                        string path = @"DownloadFolder\" + filename;
                                        using (var fileStream = System.IO.File.Create(path))



    This perfectly works fine if the container has direct file in child directory
    Container: Photos
    filename : anil.jpg

    but if i have below structure it does not work.

    Container: Photos
    filename : test/guid23434324335/logs/anil.jpg

    Can you please help in this regard on how to traverse and downlaod anil.jpg

    Friday, December 11, 2015 11:55 AM

All replies