SALES: 1-800-867-1380
This topic has not yet been rated - Rate this topic

CloudBlob.BeginFetchAttributes Method (BlobRequestOptions, AsyncCallback, Object)

Updated: April 24, 2013

[This topic is part of the Windows Azure Storage Client Library 1.7, which has been deprecated. The current recommended version is Storage Client Library 3.0.]

Begins an asynchronous operation to populate the blob's properties and metadata, using a conditional request based on the BlobRequestOptions that you specify.

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

public IAsyncResult BeginFetchAttributes (
	BlobRequestOptions options,
	AsyncCallback callback,
	Object state



Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions

An object that specifies any additional options for the request.


Type: System.AsyncCallback

The callback delegate that will receive notification when the asynchronous operation completes.


Type: System.Object

A user-defined object that will be passed to the callback delegate.

Return Value

Type: System.IAsyncResult

An IAsyncResult that references the asynchronous operation.

The following code example creates an instance of a blob in the cloud, and populates it with metadata. It then creates a second blob that references the same blob instance, and populates it’s properties and metatdata using an asynchronous call—specifying request options.

private void Eg_AsyncListBlobPropertiesAndMetadata2(Uri blobEndpoint, string accountName, string accountKey)
    // Create a service client for credentialed access to the Blob service.
    CloudBlobClient blobClient =
        new CloudBlobClient(blobEndpoint,
            new StorageCredentialsAccountAndKey(accountName, accountKey));

    // Create a blob reference.
    CloudBlob myBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // Write text to the blob.
    myBlob.UploadText("One man that has a mind and knows it can always beat ten men who haven't and don't.");

    // Define metadata for the blob.
    myBlob.Metadata["category"] = "quotes";
    myBlob.Metadata["owner"] = "George Bernard Shaw";

    // Update the blob instance with the new metadata.

    // Create a second blob reference, that references the same blob instance.
    CloudBlob myBlob2 = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // Set options for the request. E.g., Specify an operation timeout of 20 seconds.
    BlobRequestOptions options = new BlobRequestOptions();

    options.Timeout = TimeSpan.FromSeconds(20.0);

    // At this point, myBlob2 has neither system properties nor metadata.
    // Populate the blob's attributes.
    // Use aResult to determine when this asynchronous call has completed.
    IAsyncResult aResult = myBlob2.BeginFetchAttributes(options, Eg_BeginFetchAttributesCallback, myBlob2);

    // The properties and metatdata won't appear on the blob 
    // until the asynchronous call has completed.
    while (!aResult.IsCompleted)
        // The calling thread can perfrom other work while the asynchronous call completes.

    // Verify that myBlob2's properties and metadata have in fact been populated.
    Console.WriteLine("Blob:\t" + myBlob2.Attributes.Uri);
    Console.WriteLine("Blob properties:");
    Console.WriteLine("BlobType:\t\t" + myBlob2.Attributes.Properties.BlobType);
    Console.WriteLine("LastModifiedUTC:\t" + myBlob2.Attributes.Properties.LastModifiedUtc);
    Console.WriteLine("ETag:\t" + myBlob2.Attributes.Properties.ETag);

    //Enumerate the blob's metadata.
    foreach (var metadataKey in myBlob2.Metadata.Keys)
        Console.WriteLine("Metadata name:\t" + metadataKey.ToString());
        Console.WriteLine("Metadata value:\t" + myBlob2.Metadata.Get(metadataKey.ToString()));

private void Eg_BeginFetchAttributesCallback(IAsyncResult result)
    CloudBlob blobForAttributes = (CloudBlob)result.AsyncState;

The BeginFetchAttributes method begins an operation to populate the blob's system properties and user-defined metadata. Before reading a blob's properties or metadata, you should always call this method or the FetchAttributes method to retrieve the latest values for the blob's properties and metadata from the service.

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 and Windows Server 2008

Target Platforms

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.