2

I have in Azure Storage a Blob Container, then a folder, then a subfolder, and then different files(ContainerName/Folder1/Subfolder1/files...). How can I read all the files in that Subfolder1 directory? Let's say I have some pdf files in there and I need to get them in my application, how would I do that?

3
  • Do you want to read the contents of the files or just list them? Also please tell us if the container ACL is set as Private or not? Commented May 26, 2017 at 13:22
  • For the moment I just want to list them, the container ACL is private. I have tried with ListBlobs() using the container reference but it only lists the folders of the fitst level(Folder1, Folder2, etc, not Subfolder1... etc) Commented May 26, 2017 at 13:23
  • stackoverflow.com/questions/51855853/… you can try this way as well. Commented Aug 20, 2018 at 3:04

1 Answer 1

9

Well, it's not really a subfolder, it's just a path.

As the documentation for ListBlobs says:

You can optionally specify a blob prefix to list blobs whose names begin with the same string. If you use a delimiter character in your blob names to create a virtual directory structure, the blob prefix can include all or part of the virtual directory structure (but not the container name).

So you would use pass in Folder1/Subfolder1 as the prefix:

var container = blobClient.GetContainerReference(containerName);
foreach (var file in container.ListBlobs(prefix: "Folder1/Subfolder1", useFlatBlobListing: true))
{ 
    // etc

Note: I do not remember offhand whether the prefix needs a leading or trailing slash or both or neither..

prefix parameter ensures that only blobs names of which start with the parameter's value will be returned as part of listing. useFlatBlobListing parameter will ensure that if there are any blobs in the nested folders inside the subfolder specified in prefix are also returned.

Sign up to request clarification or add additional context in comments.

1 Comment

You just beat me by a minute :). Is it OK if I update your answer? There's one bit more information I want to provide.

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.