1

I'm trying to use the Azure Storage SDK and trying to determine if there's a way I can specify a container and find the number of blobs it contains. The posts I've seen thus far only mention checking by the name of the blob, which doesn't suit my needs.

If I do the following:

CloudBlobContainer blobContainer = blobClient.GetContainerReference("my-container");
var blobCount = blobContainer.ListBlobs().Count();

Then I'm hit with a HTTP 404 Exception.

Is there any way to go about this?

RizJa
  • 1,961
  • 1
  • 21
  • 38
  • I'm wondering why you got HTTP 404 exception. The code should have worked well. Could you paste the value of StorageException.ToString() here? – Zhaoxing Lu Jul 21 '16 at 09:07

1 Answers1

0

You can check the count by using this code:

CloudBlobContainer blobContainer = blobClient.GetContainerReference("my-container");
blobContainer.FetchAttributes();
string count = blobContainer.Metadata["ItemCount"];
int ItemCount;
if(int.Tryparse(count ,out ItemCount))
{
   if(ItemCount>0)
    // Container is not Empty
   else
    // Container is Empty  
}
else
{
  // Conversion failed;
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88