BlobStorage.Advanced.ListBlobsFlatListingAsync C# (CSharp) Method

ListBlobsFlatListingAsync() private static method

Lists blobs in the specified container using a flat listing, with an optional segment size specified, and writes their properties and metadata to the console window. The flat listing returns a segment containing all of the blobs matching the listing criteria. In a flat listing, blobs are not organized by virtual directory.
private static ListBlobsFlatListingAsync ( Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container, int segmentSize ) : System.Threading.Tasks.Task
container Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer A CloudBlobContainer object.
segmentSize int The size of the segment to return in each call to the listing operation.
return System.Threading.Tasks.Task
        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;
            }
        }