CloudBlobClient.GetBlobReference Method (String, Nullable)

Storage Client Library NET API

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

Visual Basic
Dim instance As CloudBlobClient
Dim blobAddress As String
Dim snapshotTime As Nullable(Of DateTime)
Dim returnValue As CloudBlob

returnValue = instance.GetBlobReference(blobAddress, snapshotTime)

Syntax

Visual Basic
Public Function GetBlobReference ( _
	blobAddress As String, _
	snapshotTime As Nullable(Of DateTime) _
) As CloudBlob
C#
public CloudBlob GetBlobReference (
	string blobAddress,
	Nullable<DateTime> snapshotTime
)
C++
public:
CloudBlob^ GetBlobReference (
	String^ blobAddress, 
	Nullable<DateTime> snapshotTime
)
J#
JScript

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.

Example

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

C# Copy Code
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));
}

Remarks

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.


Thread Safety

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

Platforms

Development Platforms

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

Change History

See Also