1

I'm trying through iterate through blobs from a container, but I'm getting errors. I'm using the following code from Microsoft Docs: One of the main errors I'm getting is when calling the ToListAsync() method

// Iterate through the blobs in a container
List<BlobItem> segment = await blobContainer.GetBlobsAsync(prefix: "").ToListAsync();
foreach (BlobItem blobItem in segment)
{
    BlobClient blob = blobContainer.GetBlobClient(blobItem.Name);
    // Check the source file's metadata
    Response<BlobProperties> propertiesResponse = await blob.GetPropertiesAsync();
    BlobProperties properties = propertiesResponse.Value;
    
    // Check the last modified date and time
    // Add the blob to the list if has been modified since the specified date and time
    if (DateTimeOffset.Compare(properties.LastModified.ToUniversalTime(), transferBlobsModifiedSince.ToUniversalTime()) > 0)
    {
        blobList.Add(blob);
    }
}

These are the errors: enter image description here

enter image description here

1
  • What is the error? Please provide the exact text of the error message and indicate what line it came from. Commented Jun 22, 2022 at 21:17

1 Answer 1

1

From https://learn.microsoft.com/en-us/dotnet/azure/sdk/pagination#use-systemlinqasync-with-asyncpageable

The System.Linq.Async package provides a set of LINQ methods that operate on IAsyncEnumerable<T> type. Because AsyncPageable<T> implements IAsyncEnumerable<T>, you can use System.Linq.Async to query and transform the data.

So make sure you have the System.Linq.Async package included in your project, along with a using System.Linq.Async; directive in your C# file.

Just be aware that there's a reason this is using an IAsyncEnumerable<>: if you have a lot of blobs it might be better to stream your way through the collection rather than loading all the values into an in-memory list.

IAsyncEnumerable<BlobItem> segment = blobContainer.GetBlobsAsync(prefix: "");
await foreach (BlobItem blobItem in segment)
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.