3

I've reviewed this: Getting list of names of Azure blob files in a container?

and this: https://feedback.azure.com/forums/287593-logic-apps/suggestions/16252474-list-files-in-folder-on-azure-blob-storage

But I have not found any code examples of how to list the files in a particular virtual folder within a container using c#. This is as far as I got. I do not see any way to specify a file path in the ListBlobs ()method.

        var blobStorageAccount = GetStorageAccount();
        var blobClient = blobStorageAccount.CreateCloudBlobClient();
        var blobContainer = blobClient.GetContainerReference(containerName);
        List<string> blobNames = blobContainer.ListBlobs().OfType<CloudBlockBlob>().Select(b => b.Name).ToList();

2 Answers 2

6

There is no such thing as a subfolder. You have containers containing blobs. You do have virtual folders, for example

/container/virtualfolder/myblob

The container name is container and the blob name is virtualfolder/myblob

You can list all blobs in a virtual folder using the prefix parameter (see the docs):

        var blobStorageAccount = GetStorageAccount();
        var blobClient = blobStorageAccount.CreateCloudBlobClient();
        var blobContainer = blobClient.GetContainerReference(containerName);
        List<string> blobNames = blobContainer.ListBlobs(prefix: "virtualfolder").OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
Sign up to request clarification or add additional context in comments.

2 Comments

That worked. Thanks! Is there a built in way to isolate the blob name from the virtual path? Or, perhaps Path.GetFileName() will work
Hmm not sure. Path.GetFileName() might work, or you can try a .Split('/').Last()
2

Microsoft.Azure.Storage.Blob is deprecated. Using Azure.Storage.Blob looks like it would be:

List<string> blobNames = blobContainer.GetBlobs(prefix: "virtualfolder").Select(b => b.Name).ToList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.