How to get size of Azure CloudBlobContainer
.net, azure-storage, c#
Solution
FYI here's the answer. Hope this helps.
public static long GetSpaceUsed(string containerName)
{
var container = CloudStorageAccount
.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString)
.CreateCloudBlobClient()
.GetContainerReference(containerName);
if (container.Exists())
{
return (from CloudBlockBlob blob in
container.ListBlobs(useFlatBlobListing: true)
select blob.Properties.Length
).Sum();
}
return 0;
}
Problem
I'm creating a .net wrapper service for my application that utilizes Azure Blob Storage as a file store. My application creates a new `CloudBlobContainer` for each "account" on my system. Each account is limited to a maximum amount of storage. What is the simplest and most efficient way to query the current size (space utilization) of an Azure CloudBlobContainer`?