Search code examples
c#azureazure-storage

Azure Storage container size


How can I get a size of container in Azure Storage? I access Azure storage via C# API:

var account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStoragePrimary"]);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("myContainer");

Solution

  • I have updated Microsoft.WindowsAzure.StorageClient.dll 1.1.0.0 from Windows Azure SDK to Microsoft.WindowsAzure.Storage.dll 2.0.0.0 from Windows Azure Storage NuGet package and it works now.

    long size = 0;
    var list = container.ListBlobs();
    foreach (CloudBlockBlob blob in list) {
        size += blob.Properties.Length;
    }