Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

c# - How to load list of Azure blob files recursively?

Azure blob files are stored in a plain list without any physical folder structure, but we can create virtual folders where each file's folder path is a part of its name.

It brings out another problem, how to retrieve a list of ALL files in virtual sub-folder, using only that folder's name?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, there's a simpler way to do that and it is available in the library itself. If you look at CloudBlobContainer.ListBlobs method, it accepts two parameters:

  1. prefix: This is the name of your directory. If it is a nested directory, you will need to specify the full path e.g. myfolder/mysubfolder.
  2. useFlatBlobListing: Setting this value to true will ensure that only blobs are returned (including inside any sub folders inside that directory) and not directories and blobs.

    var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
    var blobClient = account.CreateCloudBlobClient();
    var container = blobClient.GetContainerReference("blob-container-name");
    var blobs = container.ListBlobs(prefix: "container-directory", useFlatBlobListing: true);
    

You will get a list of all blobs belonging in the "container-directory" in blobs variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...