/// <summary> /// Gets the children of the container (if the uri has segments) /// or containers in the storage account (if the uri has no segments) /// </summary> public IEnumerable <Uri> GetChildren(Uri directoryUri) { string[] segments = directoryUri.Segments; BlobContinuationToken blobContinuationToken = null; // If at the root, return all containers if (segments.Length <= 1) { do { ContainerResultSegment containerListing = _client.ListContainersSegmented(blobContinuationToken); if (containerListing?.Results != null) { foreach (CloudBlobContainer containerItem in containerListing.Results) { yield return(containerItem.Uri); } } blobContinuationToken = containerListing?.ContinuationToken; }while (blobContinuationToken != null); yield break; } // If not at the root folder, return all blobs within the container string containerName = segments[1]; string relativeAddress = directoryUri.PathAndQuery.Substring(containerName.Length + 1); do { BlobResultSegment listing = _client.ListBlobsSegmented( containerName, relativeAddress, useFlatListing: false, BlobListingDetails.None, maxResults: null, blobContinuationToken, new BlobRequestOptions(), new OperationContext()); if (listing == null || listing.Results.Count() == 0) { throw new ArgumentException( "Call to ListBlobsSegmented returned no results. Uri is invalid or does not have children.", nameof(directoryUri)); } foreach (IListBlobItem listBlobItem in listing.Results) { yield return(listBlobItem.Uri); } blobContinuationToken = listing.ContinuationToken; }while (blobContinuationToken != null); }
/// <summary> /// Gets the children of the blob "directory." /// </summary> public IEnumerable <Uri> GetChildren(Uri directoryUri) { BlobContinuationToken blobContinuationToken = null; var path = directoryUri.AbsolutePath.Trim('/'); do { var listing = _client.ListBlobsSegmented(path, false, BlobListingDetails.None, null, blobContinuationToken, new BlobRequestOptions(), new OperationContext()); if (listing.Results != null) { foreach (var listBlobItem in listing.Results) { yield return(listBlobItem.Uri); } } blobContinuationToken = listing.ContinuationToken; }while (blobContinuationToken != null); }