blobazure-blob-storageblobstoreblobstorage

Unable to Read Blob Storage account Directories and sub Directories


I am trying to read directories and sub directories of the storage account and unable to read, below is the sample code and attached blob container structure snapshot

sample code:

  CloudBlobContainer container = Retrier<CloudBlobContainer>.TryWithDelayIncremental(() => blobclient.GetContainerReference(ContainerName), NoOfRetries, DelayInMilliSecs);

var directory = container.GetDirectoryReference(@"policies /Initiatives");
            var folders = directory.ListBlobs().Where(b => b as CloudBlobDirectory != null).ToList();
            foreach (var folder in folders)
            {
                Console.WriteLine(folder.Uri);
            }

folder structure:

folder structure

container and folder:

container and folder


Solution

  • Based on your capture, policies is the name of your container, if you want to get all URIs of folders under /Initiatives in container policies, you should not involve container name in directory reference name, try the code below :

        CloudBlobContainer container = blobClient.GetContainerReference("policies");
    
        var directory = container.GetDirectoryReference(@"Initiatives");
        var folders = directory.ListBlobs().Where(b => b as CloudBlobDirectory != null).ToList();
        foreach (var folder in folders)
        {
            Console.WriteLine(folder.Uri);
        }
    

    Test result on my side : enter image description here enter image description here