Exporter (0) Imprimer
Développer tout
EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

CloudBlobClient.ListBlobsWithPrefix Method (String, BlobRequestOptions)

Updated: April 24, 2011

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Returns an enumerable collection of blob items whose names begin with the specified prefix, that are retrieved lazily, using a conditional request based on the BlobRequestOptions that you specify.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

'Utilisation
Dim instance As CloudBlobClient
Dim prefix As String
Dim options As BlobRequestOptions
Dim returnValue As IEnumerable(Of IListBlobItem)

returnValue = instance.ListBlobsWithPrefix(prefix, options)

public IEnumerable<IListBlobItem> ListBlobsWithPrefix (
	string prefix,
	BlobRequestOptions options
)

Parameters

prefix

Type: System.String

The blob name prefix. This value must be preceded by the name of the container.

options

Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions

An object that specifies any additional options for the request.

Return Value

Type: System.Collections.Generic.IEnumerable

An enumerable collection of objects that implement IListBlobItem and are retrieved lazily.

The following code example lists blobs beginning with a specified prefix. Note that the prefix must include the name of the container.

static void ListBlobsInVirtualDirectory(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));

    //List blobs in container 'mycontainer' beginning with prefix 'a/', using a hierarchical listing.
    //The results list only blobs directly beneath 'mycontainer/a/'
    foreach (var blobItem in blobClient.ListBlobsWithPrefix("mycontainer/a/"))
    {
        Console.WriteLine(blobItem.Uri);
    }

    //Results similar to:
    //http://storagesample.blob.core.windows.net/mycontainer/a/00001.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/

    Console.WriteLine();

    //List blobs in container 'mycontainer' beginning with prefix 'a/', using a flat listing.
    //The results list all blobs beneath 'mycontainer/a/', even if they are in a virtual subdirectory.
    BlobRequestOptions options = new BlobRequestOptions();
    options.UseFlatBlobListing = true;
    foreach (var blobItem in blobClient.ListBlobsWithPrefix("mycontainer/a/", options))
    {
        Console.WriteLine(blobItem.Uri);
    }

    //Results similar to:
    //http://storagesample.blob.core.windows.net/mycontainer/a/00001.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/00002.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/c/00003.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/c/00004.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/c/00005.txt
    //http://storagesample.blob.core.windows.net/mycontainer/a/b/c/00006.txt
}


The types of objects returned by the ListBlobsWithPrefix method depend on the type of listing that is being performed. If the UseFlatBlobListing property is set to true, ListBlobsWithPrefix will return an enumerable collection of CloudBlob objects. If UseFlatBlobListing is set to false (the default value), the listing may return a collection containing CloudBlob objects and CloudBlobDirectory objects. The latter case provides a convenience for subsequent enumerations over a virtual blob hierarchy.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

 

Afficher:
© 2014 Microsoft