CloudBlobClient.ListBlobsWithPrefixSegmented Method (String, Int32, ResultContinuation) |
See Also Example |
Returns a result segment containing a collection of blob items whose names begin with the specified prefix. Use this overload when you want to control the maximum number of results returned at a time, and when you want to use a continuation token to determine whether there are more results to return from the service after the current page completes. Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Usage
Visual Basic |
---|
Dim instance As CloudBlobClient Dim prefix As String Dim maxResults As Integer Dim continuationToken As ResultContinuation Dim returnValue As ResultSegment(Of IListBlobItem) returnValue = instance.ListBlobsWithPrefixSegmented(prefix, maxResults, continuationToken) |
Syntax
Visual Basic |
---|
Public Function ListBlobsWithPrefixSegmented ( _ prefix As String, _ maxResults As Integer, _ continuationToken As ResultContinuation _ ) As ResultSegment(Of IListBlobItem) |
C# |
---|
public ResultSegment<IListBlobItem> ListBlobsWithPrefixSegmented ( string prefix, int maxResults, ResultContinuation continuationToken ) |
C++ |
---|
public: ResultSegment<IListBlobItem^>^ ListBlobsWithPrefixSegmented ( String^ prefix, int maxResults, ResultContinuation^ continuationToken ) |
J# |
---|
JScript |
---|
Parameters
- prefix
Type: System.String
The blob name prefix. This value must be preceded by the name of the container.
- maxResults
Type: System.Int32
A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the per-operation limit of 5000.
- continuationToken
Type: Microsoft.WindowsAzure.StorageClient.ResultContinuation
A continuation token returned by a previous listing operation.
Return Value
Type: Microsoft.WindowsAzure.StorageClient.ResultSegment A result segment containing objects that implement IListBlobItem.Example
The following code example returns blobs in segments, using a flat listing.
C# | Copy Code |
---|---|
static void ListBlobsInSegments(Uri blobEndpoint, string accountName, string accountKey) { //Create service client for credentialed access to the Blob service. CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey)); //Return blobs using a flat listing. BlobRequestOptions options = new BlobRequestOptions(); options.UseFlatBlobListing = true; //List blobs in container 'lotsofblobs' beginning with prefix '0', using a flat listing. //This first operation will return up to 5000 blobs. ResultSegment<IListBlobItem> resultSegment = blobClient.ListBlobsWithPrefixSegmented("lotsofblobs/0", options); foreach (var blobItem in resultSegment.Results) { Console.WriteLine(blobItem.Uri); } ResultContinuation continuationToken = resultSegment.ContinuationToken; //Check whether there are more results. while (continuationToken != null) { resultSegment = resultSegment.GetNext(); foreach (var blobItem in resultSegment.Results) { Console.WriteLine(blobItem.Uri); } continuationToken = resultSegment.ContinuationToken; } } |
Remarks
The ListBlobsWithPrefixSegmented method lists blobs in pages. A page is set of results of a specified size; it is represented by the ResultSegment class. By returning blobs in pages, you can control the number of blobs returned per operation. This may be useful if, for example, you are displaying a web page with some predefined number of blobs on it.
To specify the page size to return, pass in a non-zero value for the maxResults parameter. Passing in zero for the maxResults parameter returns either the maximum number of results available, or the per-operation limit of 5000 results.
If you have specified a page size, you can check the HasMoreResults property to check whether the page is complete. If HasMoreResults is true, the complete page has not been returned for some reason. Call GetNext to return the remaining results in the page.
Note that if you have not specified a page size, HasMoreResults will always be false.
Check the value of the ContinuationToken property to determine whether there are more results to return from the service after the page is complete. The continuation token is non-null as long as there are more results to return from the service. If the page is complete, then HasMoreResults will be false, but if the continuation token is non-null, there are additional results to return beyond that page.
Call the GetNext method to return the next segment of results from the service.