0

As the title mentions, I am trying to loop through blobs within a container. Right now I have a storage account with a blob container containing .txt files. But I also have a couple of blob directories (e.g. containerName/anotherFolder/more.txt)

Currently my code looks like this.

        container = blobClient.GetContainerReference("myContainer");
        BlobResultSegment allBlobs = await container.ListBlobsSegmentedAsync(null);

        foreach (IListBlobItem blob in allBlobs.Results)
        {
            try
            {
                CloudBlockBlob blockblob = (CloudBlockBlob)blob;
                ...
                ...
                ...
            }                
            catch(Exception e)
            {
                continue;
            }
        }

I am wondering if there is a better way than using a try/catch statement. Currently I have it because folders cannot be cast to cloudBlockBlobs.

*Note, I do not need the files within the folder, only the blobs within the first container.

Razoll
  • 107
  • 1
  • 1
  • 7
  • I have closed this question as duplicate assuming you would like to list all blobs in a container. If that's not the case, please provide a comment and I will reopen it. – Gaurav Mantri Sep 20 '19 at 02:28

1 Answers1

1
if (null == blob as CloudBlockBlob)
{
...
}

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73