Getting filenames from azure storage given url folder path Getting filenames from azure storage given url folder path azure azure

Getting filenames from azure storage given url folder path


Here's how you can do this:
1. Create blob client:

var account = new CloudStorageAccount(new StorageCredentials("myazurestorage", YOUR_API_KEY), true);var blobClient = account.CreateCloudBlobClient();  

2. Get container:

var container = blobClient.GetContainerReference("acessibleimages");

3. Use ListBlobs like this (read more about flat blob listing):

var blobList= container.ListBlobs(prefix: "folder/folder", useFlatBlobListing: true);
  1. After you have your list of blobs you can iterate through them and extract path like this: foreach (var blob in blobs){blob.StorageUri.PrimaryUri;}


RAS's answer is correct but I have a solution with only two steps.Since, according to the official document, there is also a ListBlobs function in the CloudBlobClient class, we can get the blobs without creating the container object. the following are the steps:

  1. Create blob client:
var account = new CloudStorageAccount(new StorageCredentials("myazurestorage", YOUR_API_KEY), true);var blobClient = account.CreateCloudBlobClient();
  1. Use ListBlobs like this:
var blobList= container.ListBlobs(prefix: "folder/folder/", useFlatBlobListing: true);

Be noticed of the ending forward slash(/). if not added, the function returns the folder per se. if added, returns the blobs in the folder.

And unlike web development, if the prefix starts with "/", it will not work and return 404 (cannot find page.)

Also Azure Storage is case sensitive.

Use useFlatBlobListing, according to what you want. Why microsoft just use the word recursive? I think recursive is better.