CloudBlobClient Class

CloudBlobClient Class

 

Updated: August 17, 2016

Provides a client-side logical representation of Microsoft Azure Blob storage.

Namespace:   Microsoft.WindowsAzure.Storage.Blob
Assembly:  Microsoft.WindowsAzure.Storage (in Microsoft.WindowsAzure.Storage.dll)

System.Object
  Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient

public class CloudBlobClient

NameDescription
System_CAPS_pubmethodCloudBlobClient(StorageUri, StorageCredentials)

Initializes a new instance of the CloudBlobClient class using the specified Blob service endpoint and account credentials.

System_CAPS_pubmethodCloudBlobClient(Uri)

Initializes a new instance of the CloudBlobClient class using the specified Blob service endpoint and anonymous credentials.

System_CAPS_pubmethodCloudBlobClient(Uri, StorageCredentials)

Initializes a new instance of the CloudBlobClient class using the specified Blob service endpoint and account credentials.

NameDescription
System_CAPS_pubpropertyAuthenticationScheme

Gets or sets the authentication scheme to use to sign HTTP requests.

System_CAPS_pubpropertyBaseUri

Gets the base URI for the Blob service client at the primary location.

System_CAPS_pubpropertyBufferManager

Gets or sets a buffer manager that implements the IBufferManager interface, specifying a buffer pool for use with operations against the Blob service client.

System_CAPS_pubpropertyCredentials

Gets the account credentials used to create the Blob service client.

System_CAPS_pubpropertyDefaultDelimiter

Gets or sets the default delimiter that may be used to create a virtual directory structure of blobs.

System_CAPS_pubpropertyDefaultRequestOptions

Gets or sets the default request options for requests made via the Blob service client.

System_CAPS_pubpropertyRetryPolicy

Obsolete. Gets or sets the default retry policy for requests made via the Blob service client.

System_CAPS_pubpropertyStorageUri

Gets the Blob service endpoints for both the primary and secondary locations.

NameDescription
System_CAPS_pubmethodBeginGetBlobReferenceFromServer(StorageUri, AccessCondition, BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to get a reference to a blob.

System_CAPS_pubmethodBeginGetBlobReferenceFromServer(Uri, AccessCondition, BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to get a reference to a blob.

System_CAPS_pubmethodBeginGetBlobReferenceFromServer(Uri, AsyncCallback, Object)

Begins an asynchronous operation to get a reference to a blob.

System_CAPS_pubmethodBeginGetServiceProperties(AsyncCallback, Object)

Begins an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodBeginGetServiceProperties(BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodBeginGetServiceStats(AsyncCallback, Object)

Begins an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodBeginGetServiceStats(BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodBeginListBlobsSegmented(String, BlobContinuationToken, AsyncCallback, Object)

Begins an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodBeginListBlobsSegmented(String, Boolean, BlobListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodBeginListContainersSegmented(BlobContinuationToken, AsyncCallback, Object)

Begins an asynchronous request to return a result segment containing a collection of containers.

System_CAPS_pubmethodBeginListContainersSegmented(String, BlobContinuationToken, AsyncCallback, Object)

Begins an asynchronous request to return a result segment containing a collection of containers.

System_CAPS_pubmethodBeginListContainersSegmented(String, ContainerListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous request to return a result segment containing a collection of containers whose names begin with the specified prefix.

System_CAPS_pubmethodBeginSetServiceProperties(ServiceProperties, AsyncCallback, Object)

Begins an asynchronous operation to set service properties for the Blob service.

System_CAPS_pubmethodBeginSetServiceProperties(ServiceProperties, BlobRequestOptions, OperationContext, AsyncCallback, Object)

Begins an asynchronous operation to set service properties for the Blob service.

System_CAPS_pubmethodEndGetBlobReferenceFromServer(IAsyncResult)

Ends an asynchronous operation to get a reference to a blob.

System_CAPS_pubmethodEndGetServiceProperties(IAsyncResult)

Ends an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodEndGetServiceStats(IAsyncResult)

Ends an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodEndListBlobsSegmented(IAsyncResult)

Ends an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodEndListContainersSegmented(IAsyncResult)

Ends an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodEndSetServiceProperties(IAsyncResult)

Ends an asynchronous operation to set service properties for the Blob service.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetBlobReferenceFromServer(StorageUri, AccessCondition, BlobRequestOptions, OperationContext)

Gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServer(Uri, AccessCondition, BlobRequestOptions, OperationContext)

Gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(StorageUri, AccessCondition, BlobRequestOptions, OperationContext)

Initiates an asynchronous operation that gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(StorageUri, AccessCondition, BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation that gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(Uri)

Initiates an asynchronous operation that gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(Uri, AccessCondition, BlobRequestOptions, OperationContext)

Returns a Task<TResult> object that gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(Uri, AccessCondition, BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation that gets a reference to a blob.

System_CAPS_pubmethodGetBlobReferenceFromServerAsync(Uri, CancellationToken)

Initiates an asynchronous operation that gets a reference to a blob.

System_CAPS_pubmethodGetContainerReference(String)

Returns a reference to a CloudBlobContainer object with the specified name.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetRootContainerReference()

Returns a reference to the root container.

System_CAPS_pubmethodGetServiceProperties(BlobRequestOptions, OperationContext)

Gets service properties for the Blob service.

System_CAPS_pubmethodGetServicePropertiesAsync()

Initiates an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodGetServicePropertiesAsync(BlobRequestOptions, OperationContext)

Initiates an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodGetServicePropertiesAsync(BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodGetServicePropertiesAsync(CancellationToken)

Initiates an asynchronous operation to get service properties for the Blob service.

System_CAPS_pubmethodGetServiceStats(BlobRequestOptions, OperationContext)

Gets service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodGetServiceStatsAsync()

Initiates an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodGetServiceStatsAsync(BlobRequestOptions, OperationContext)

Initiates an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodGetServiceStatsAsync(BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodGetServiceStatsAsync(CancellationToken)

Initiates an asynchronous operation to get service stats for the secondary Blob service endpoint.

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodListBlobs(String, Boolean, BlobListingDetails, BlobRequestOptions, OperationContext)

Returns an enumerable collection of blobs in the container, retrieved lazily.

System_CAPS_pubmethodListBlobsSegmented(String, BlobContinuationToken)

Returns a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListBlobsSegmented(String, Boolean, BlobListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext)

Returns a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListBlobsSegmentedAsync(String, BlobContinuationToken)

Initiates an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListBlobsSegmentedAsync(String, BlobContinuationToken, CancellationToken)

Initiates an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListBlobsSegmentedAsync(String, Boolean, BlobListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext)

Initiates an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListBlobsSegmentedAsync(String, Boolean, BlobListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation to return a result segment containing a collection of blob items in the container.

System_CAPS_pubmethodListContainers(String, ContainerListingDetails, BlobRequestOptions, OperationContext)

Returns an enumerable collection of containers whose names begin with the specified prefix and that are retrieved lazily.

System_CAPS_pubmethodListContainersSegmented(BlobContinuationToken)

Returns a result segment containing a collection of CloudBlobContainer objects.

System_CAPS_pubmethodListContainersSegmented(String, BlobContinuationToken)

Returns a result segment containing a collection of CloudBlobContainer objects.

System_CAPS_pubmethodListContainersSegmented(String, ContainerListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext)

Returns a result segment containing a collection of containers whose names begin with the specified prefix.

System_CAPS_pubmethodListContainersSegmentedAsync(BlobContinuationToken)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodListContainersSegmentedAsync(BlobContinuationToken, CancellationToken)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodListContainersSegmentedAsync(String, BlobContinuationToken)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodListContainersSegmentedAsync(String, BlobContinuationToken, CancellationToken)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodListContainersSegmentedAsync(String, ContainerListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_pubmethodListContainersSegmentedAsync(String, ContainerListingDetails, Nullable<Int32>, BlobContinuationToken, BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation to return a result segment containing a collection of containers.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodSetServiceProperties(ServiceProperties, BlobRequestOptions, OperationContext)

Sets service properties for the Blob service.

System_CAPS_pubmethodSetServicePropertiesAsync(ServiceProperties)

Initiates an asynchronous operation that sets service properties for the Blob service.

System_CAPS_pubmethodSetServicePropertiesAsync(ServiceProperties, BlobRequestOptions, OperationContext)

Initiates an asynchronous operation that sets service properties for the Blob service.

System_CAPS_pubmethodSetServicePropertiesAsync(ServiceProperties, BlobRequestOptions, OperationContext, CancellationToken)

Initiates an asynchronous operation that sets service properties for the Blob service.

System_CAPS_pubmethodSetServicePropertiesAsync(ServiceProperties, CancellationToken)

Initiates an asynchronous operation that sets service properties for the Blob service.

System_CAPS_pubmethodToString()

(Inherited from Object.)

The Blob service client provides an abstraction for developing against Azure Blob storage. This object serves as an entry point in your code for programming with blobs.

The Blob service client stores credentials for use in subsequent operations. Valid credentials may be your account name and account key, or a shared access signature (SAS). You may also create a service client for anonymous operations.

You can use the service client to configure settings on the Blob service itself, such as storage analytics and CORS. The service client may also store other settings for requests against Blob storage. For example, you can specify options on service client's DefaultRequestOptions object, such as a default retry policy or server timeout for all Blob service operations that use the service client.

A simple way to return an instance of a CloudBlobClient object is to create a CloudStorageAccount object to represent your account, and then call the CreateCloudBlobClient method.

Example: Parsing a connection string

Here's an example that pulls a connection string from a configuration file (such as app.config or web.config) to create the StorageAccount object. This example uses the Microsoft Azure Configuration Manager; to try it, you'll need to install that package from NuGet, and add a using statement to your code.

CloudStorageAccount storageAccount;

try
{
    // Use the Azure CloudConfigurationManager class to return a named connection string from a config file. 
    storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
}
catch (StorageException e)
{
    Console.WriteLine(e.Message);
    Console.ReadLine();
    throw;
}

// Create service client for credentialed access to the Blob service.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

In the example above, the connection string may use Shared Key authentication, or a shared access signature (SAS). For more information on connection strings for Azure Storage, see Configure Azure Storage Connection Strings.

You can also use the CloudBlobClient constructors to create a new instance. The following examples show how to use the CloudBlobClient constructors with each Azure Storage authentication scheme.

Example: Constructor with Shared Key credentials

Shared Key authentication uses your storage account name and key (available in the Azure Portal) to authenticate requests against Azure Storage. For additional information about Shared Key authentication, see Authentication for the Azure Storage Services.

// Create new credentials using account name and account key (replace the placeholder below with yours).
StorageCredentials credentialsSharedKey = new StorageCredentials("storagesample", 
    "<account-key>");
CloudBlobClient blobClientSharedKey = new CloudBlobClient(new Uri("https://storagesample.blob.core.windows.net/"), credentialsSharedKey);

// Verify that the credentials provided permit you to list blobs in the container.
CloudBlobContainer containerSharedKey = blobClientSharedKey.GetContainerReference("private-container");
foreach (var blob in containerSharedKey.ListBlobs())
{
    Console.WriteLine(blob.Uri);
}

Example: Constructor with shared access signature (SAS) credentials

A SAS provides delegated access to Azure Storage resources. A SAS is an Azure Storage resource URL with a token in the query string that encapsulates the credentials needed to access a specific resource, with specified permissions and over a specified interval of time. For additional information about SAS, see Using Shared Access Signatures (SAS).

// Create new credentials using a service SAS created on the container.
// This SAS provides read, write, list, and delete permissions.
// Note that the constructor requires only the SAS token.
StorageCredentials credentialsSAS = new StorageCredentials("?sr=c&sv=2015-02-21&st=2016-08-10T14%3A23%3A47Z&se=2016-08-13T15%3A23%3A47Z&sp=rwdl&sig=OkNf9f2EecH9mtPVztOm0978lqtYNpcEzaUg2sWrJOs%3D");
CloudBlobClient blobClientSAS = new CloudBlobClient(new Uri("https://storagesample.blob.core.windows.net/"), credentialsSAS);

// Verify that the SAS credentials permit you to list blobs in the container.
CloudBlobContainer containerSAS = blobClientSAS.GetContainerReference("private-container");
foreach (var blob in containerSAS.ListBlobs())
{
    Console.WriteLine(blob.Uri);
}

// Now try writing a blob to the container using the SAS.
CloudBlockBlob newBlob = containerSAS.GetBlockBlobReference("new-block-blob.txt");
newBlob.UploadText("this is a new blob");

Example: Constructor for anonymous public access

Blobs in a public container are available for anonymous access. For additional details, see Manage anonymous read access to containers and blobs.

// Create service client for anonymous access.
CloudBlobClient blobClientAnonymous = new CloudBlobClient(new Uri("https://storagesample.blob.core.windows.net/"));

// Verify that you can use this service client to anonymously list blobs in the container.
CloudBlobContainer containerAnonymous = blobClientAnonymous.GetContainerReference("public-container");
foreach(var blob in containerAnonymous.ListBlobs())
{
    Console.WriteLine(blob.Uri);
}

Call GetContainerReference to return a reference to a container. Note that this method does not make a request against Blob storage. So you can return a reference to a container whether or not it exists.

This example shows how to return a reference to a container, and then create the container:

private static async Task<CloudBlobContainer> CreateSampleContainer(CloudBlobClient blobClient)
{
    // Name sample container based on new GUID, to ensure uniqueness.
    string containerName = ContainerPrefix + Guid.NewGuid();

    // Get a reference to a sample container.
    CloudBlobContainer container = blobClient.GetContainerReference(containerName);

    try
    {
        // Create the container if it does not already exist.
        await container.CreateIfNotExistsAsync();
    }
    catch (StorageException e)
    {
        // Ensure that the storage emulator is running if using emulator connection string.
        Console.WriteLine(e.Message);
        Console.ReadLine();
        throw;
    }

    return container;
}

A root container serves as a default container for your storage account. A blob stored in the root container may be addressed without referencing the root container name, so that a blob can be addressed at the top level of the storage account hierarchy.

A storage account may have one root container. The root container must be explicitly created and must be named $root.

This example shows how to create the root container if it does not already exist. It returns a reference to the root container by calling GetRootContainerReference:

        async public static Task CreateRootContainer(CloudBlobClient blobClient)
        {
            //Get a reference to the root container.
            CloudBlobContainer container = blobClient.GetRootContainerReference();

            //Create the root container if it does not exist.
            //Note that the root container must be explicitly created for the storage account.
            if (await container.CreateIfNotExistsAsync() == true)
            {
                Console.WriteLine("Created {0}", container.Name);
            }
            else
            {
                Console.WriteLine("{0} already exists", container.Name);
            }
            Console.WriteLine();
}

The code example below demonstrates the synchronous ListContainers method. This method returns all containers in the storage account, or the subset of containers that begin with a specified prefix.

System_CAPS_noteNote

Microsoft recommends that you call asynchronous methods in your code whenever possible for optimal performance. For more information about asynchronous programming in .NET, see Asynchronous Programming with Async and Await (C# and Visual Basic).

private static void ListAllContainers(CloudBlobClient blobClient)
{
    // List all containers in this storage account.
    Console.WriteLine("List all containers in account:");

    try
    {
        foreach (var container in blobClient.ListContainers())
        {
            Console.WriteLine("\tContainer:" + container.Name);
        }

        Console.WriteLine();
    }
    catch (StorageException e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
        throw;
    }
}

To return a segmented list of containers, call the ListContainersSegmentedAsync method. You can specify the number of results to return per segment in the maxResults parameter; if you pass in null, Azure Storage returns up to 5000 results per segment. Controlling the number of results returned helps to optimize performance, and may be useful if you are displaying results in a user interface.

If the number of results returned is less than the total number of results, Azure Storage returns a continuation token on the response. A continuation token is an opaque marker that you can pass to a subsequent listing call to return the next segment of results. The following code example shows how to use a continuation token to retrieve the next set of results, if there are still results remaining.

private static async Task ListContainersWithPrefix(CloudBlobClient blobClient, string prefix)
{
    Console.WriteLine("List all containers beginning with prefix {0}, plus container metadata:", prefix);

    BlobContinuationToken continuationToken = null;
    ContainerResultSegment resultSegment = null;

    try
    {
        do
        {
            // List containers beginning with the specified prefix, returning segments of 5 results each. 
            // Note that passing in null for the maxResults parameter returns the maximum number of results (up to 5000).
            // Requesting the container'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 blobClient.ListContainersSegmentedAsync(
                prefix, ContainerListingDetails.Metadata, 5, continuationToken, null, null);

            // Enumerate the containers returned.
            foreach (var container in resultSegment.Results)
            {
                Console.WriteLine("\tContainer:" + container.Name);

                // Write the container's metadata keys and values.
                foreach (var metadataItem in container.Metadata)
                {
                    Console.WriteLine("\t\tMetadata key: " + metadataItem.Key);
                    Console.WriteLine("\t\tMetadata value: " + metadataItem.Value);
                }
            }
        }
        while (continuationToken != null);
        Console.WriteLine();
    }
    catch (StorageException e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
        throw;
    }
}

The Blob service properties include properties for configuring storage analytics (logging and metrics), the default service version to use for executing anonymous requests, and CORS rules.

The following code example shows how to configure storage analytics for the Blob service. To run this code example, you'll need to include a using statement referencing the Microsoft.WindowsAzure.Storage.Shared.Protocol namespace.

Note that if you run this code on your own storage account, you may want to save your current service property settings and restore them once you are finished with the code example.

private static async Task ConfigureBlobAnalytics(CloudBlobClient blobClient)
{
    try
    {
        // Get current service property settings.
        ServiceProperties serviceProperties = await blobClient.GetServicePropertiesAsync();

        // Enable analytics logging and set retention policy to 14 days. 
        serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
        serviceProperties.Logging.RetentionDays = 14;
        serviceProperties.Logging.Version = "1.0";

        // Configure service properties for hourly and minute metrics. 
        // Set retention policy to 7 days.
        serviceProperties.HourMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
        serviceProperties.HourMetrics.RetentionDays = 7;
        serviceProperties.HourMetrics.Version = "1.0";

        serviceProperties.MinuteMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
        serviceProperties.MinuteMetrics.RetentionDays = 7;
        serviceProperties.MinuteMetrics.Version = "1.0";

        // Set the default service version to be used for anonymous requests.
        serviceProperties.DefaultServiceVersion = "2015-04-05";

        // Set the service properties.
        await blobClient.SetServicePropertiesAsync(serviceProperties);            
    }
    catch (StorageException e)
    {
        Console.WriteLine(e.Message);
        Console.ReadLine();
        throw;
    }
}

If your storage account is configured for read-access geo-redundant (RA-GRS) storage, you can check the status of the read-only secondary endpoint. The following code example shows how to get stats for the secondary endpoint. If the storage account is not configured for RA-GRS, the call fails with error code 403 (Forbidden).

private static async Task GetServiceStatsForSecondary(CloudBlobClient blobClient)
{
    try
    {
        // Get the URI for the secondary endpoint for Blob storage.
        Uri secondaryUri = blobClient.StorageUri.SecondaryUri;

        // Create a new service client based on the secondary endpoint.
        CloudBlobClient blobClientSecondary = new CloudBlobClient(secondaryUri, blobClient.Credentials);

        // Get the current stats for the secondary.
        // The call will fail if your storage account does not have RA-GRS enabled.
        // Change the retry policy for this call so that if it fails, it fails quickly.
        BlobRequestOptions requestOptions = new BlobRequestOptions() { RetryPolicy = new NoRetry() };
        ServiceStats blobStats = await blobClientSecondary.GetServiceStatsAsync(requestOptions, null);

        Console.WriteLine("Geo-replication status: {0}", blobStats.GeoReplication.Status);
        Console.WriteLine("Last geo-replication sync time: {0}", blobStats.GeoReplication.LastSyncTime);
        Console.WriteLine();
    }
    catch (StorageException e)
    {
        // In this case, we do not re-throw the exception, so that the sample will continue to run even if RA-GRS is not enabled
        // for this storage account.
        if (e.RequestInformation.HttpStatusCode == 403)
        {
            Console.WriteLine("This storage account does not appear to support RA-GRS.");
            Console.WriteLine("More information: {0}", e.Message);
            Console.WriteLine();
        }
        else
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
            throw;
        }
    }
}

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

Return to top
Show:
© 2016 Microsoft