I have a question about my project... I need to know how to list all folders (in a string list or something) from a Windows Azure blob storage... I allready have my BlobClient and the connection to my Azure storage.
Who can help me with this "problem"?
Blob containers contain blobs and folders (that can also contain blobs).
Go to the portal and to your storage account. Navigate to the blob container and go to properties. You can see the URL and copy it.
Users or client applications can access objects in Blob storage via HTTP/HTTPS, from anywhere in the world. Objects in Blob storage are accessible via the Azure Storage REST API, Azure PowerShell, Azure CLI, or an Azure Storage client library.
Try this code. It makes use of Storage Client library 2.0.3:
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("wad-control-container");
string blobPrefix = null;
bool useFlatBlobListing = false;
var blobs = blobContainer.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None);
var folders = blobs.Where(b => b as CloudBlobDirectory != null).ToList();
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}
If you're using Storage Client Library 1.8 (i.e. previous to version 2.0), try this code:
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference("wad-control-container");
IEnumerable<IListBlobItem> blobs = container.ListBlobs(new BlobRequestOptions()
{
UseFlatBlobListing = false,
});
var folders = blobs.Where(b => b as CloudBlobDirectory != null);
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With