private static async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int? segmentSize)
{
// List blobs to the console window.
Console.WriteLine("List blobs in segments (flat listing):");
Console.WriteLine();
int i = 0;
BlobContinuationToken continuationToken = null;
BlobResultSegment resultSegment = null;
try
{
// Call ListBlobsSegmentedAsync and enumerate the result segment returned, while the continuation token is non-null.
// When the continuation token is null, the last segment has been returned and execution can exit the loop.
do
{
// This overload allows control of the segment size. You can return all remaining results by passing null for the maxResults parameter,
// or by calling a different overload.
// Note that requesting the blob's metadata as part of the listing operation
// populates the metadata, so it's not necessary to call FetchAttributes() to read the metadata.
resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);
if (resultSegment.Results.Count() > 0)
{
Console.WriteLine("Page {0}:", ++i);
}
foreach (var blobItem in resultSegment.Results)
{
Console.WriteLine("************************************");
Console.WriteLine(blobItem.Uri);
// A flat listing operation returns only blobs, not virtual directories.
// Write out blob properties and metadata.
if (blobItem is CloudBlob)
{
PrintBlobPropertiesAndMetadata((CloudBlob)blobItem);
}
}
Console.WriteLine();
// Get the continuation token.
continuationToken = resultSegment.ContinuationToken;
} while (continuationToken != null);
}
catch (StorageException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
throw;
}
}