Export (0) Print
Expand All

CloudBlobClient.GetBlobReference Method (String, Nullable)

Updated: April 24, 2011

[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.]

Returns a reference to a blob with the specified address, and with the specified snapshot timestamp, if the blob is a snapshot.

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

'Usage

public CloudBlob GetBlobReference (
	string blobAddress,
	Nullable<DateTime> snapshotTime
)

Parameters

blobAddress

Type: System.String

The absolute URI to the blob, or a relative URI beginning with the container name.

snapshotTime

Type: System.Nullable

The snapshot timestamp, if the blob is a snapshot.

Return Value

Type: Microsoft.WindowsAzure.StorageClient.CloudBlob

A reference to a blob.

The following code example demonstrates how to get a blob snapshot using the GetBlobReference(String,Generic Nullable)method to revert changes to a blob.


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

   //Get a reference to a blob and populate it with example data.
   CloudBlob myBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");
   myBlob.UploadText("Example data.");

   // Create a snapshot of the blob.
   CloudBlob blobSnapshot1 = myBlob.CreateSnapshot();

   // Modify the example blob with a change to be reverted.
   myBlob.UploadText("Example change to be discarded.");

   // Revert the change by copying the contents of the snapshot blob back into the original.
   myBlob.CopyFromBlob(blobClient.GetBlobReference(blobSnapshot1.Uri.ToString(),blobSnapshot1.Attributes.Snapshot));
}

The GetBlobReference method returns a reference to the named blob, but it does not indicate whether the blob exists, as it does not make a round-trip to the service. If you need to ascertain the blob's existence, call a method such as FetchAttributes, and handle the resulting StorageClientException in the event the blob does not exist. The FetchAttributes method executes a HEAD request to populate the blob's properties and metadata and as such is a lightweight option for determining whether the blob exists.


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

Show:
© 2014 Microsoft