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);
- 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:
- Create blob client:
var account = new CloudStorageAccount(new StorageCredentials("myazurestorage", YOUR_API_KEY), true);var blobClient = account.CreateCloudBlobClient();
- 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.