Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List directories in Windows Azure Blob storage container

I have a question about my project... I need to know how to list all folders (in a string list or something) from a Windows Azure blob storage... I allready have my BlobClient and the connection to my Azure storage.

Who can help me with this "problem"?

like image 915
Ferry Jongmans Avatar asked Jan 24 '13 14:01

Ferry Jongmans


People also ask

Does Azure blob storage have folders?

Blob containers contain blobs and folders (that can also contain blobs).

How do you find the path to the blob storage file?

Go to the portal and to your storage account. Navigate to the blob container and go to properties. You can see the URL and copy it.

Where are blobs stored in Azure?

Users or client applications can access objects in Blob storage via HTTP/HTTPS, from anywhere in the world. Objects in Blob storage are accessible via the Azure Storage REST API, Azure PowerShell, Azure CLI, or an Azure Storage client library.


1 Answers

Try this code. It makes use of Storage Client library 2.0.3:

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("wad-control-container");
        string blobPrefix = null;
        bool useFlatBlobListing = false;
        var blobs = blobContainer.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None);
        var folders = blobs.Where(b => b as CloudBlobDirectory != null).ToList();
        foreach (var folder in folders)
        {
            Console.WriteLine(folder.Uri);
        }

If you're using Storage Client Library 1.8 (i.e. previous to version 2.0), try this code:

        var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        cloudBlobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = cloudBlobClient.GetContainerReference("wad-control-container");
        IEnumerable<IListBlobItem> blobs = container.ListBlobs(new BlobRequestOptions()
        {
            UseFlatBlobListing = false,
        });
        var folders = blobs.Where(b => b as CloudBlobDirectory != null);

        foreach (var folder in folders)
        {
            Console.WriteLine(folder.Uri);
        }
like image 162
Gaurav Mantri Avatar answered Sep 19 '22 16:09

Gaurav Mantri