How to get the size of Azure CloudBlobContainer

I am creating a .net wrapper service for my application that uses Azure Blob storage as file storage. My application creates a new one CloudBlobContainer

for each "account" on my system. Each account is limited by the maximum storage capacity.

What is the simplest and most efficient way to query the current size (space usage) of the Azure CloudBlobContainer?

+3


source to share


1 answer


FYI here is 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;
        }

      

+12


source







All Articles