KöpBuy
1-855-856-7678
SupportSupport
A snapshot is a read-only blob, and like writable blobs, it is represented by a CloudBlob object. To create a snapshot, call the CreateSnapshot method on a blob:
static void CreateSnapshot(CloudBlobClient blobClient)
{
// Reference a container
CloudBlobContainer container = new CloudBlobContainer("mycontainer", blobClient);
container.CreateIfNotExist();
// Create a blob in the container.
CloudBlob blob = container.GetBlobReference("myblob.txt");
blob.UploadText("some text");
// Create a snapshot of the blob.
CloudBlob snapshot = blob.CreateSnapshot();
// Write out the snapshot URI and snapshot time.
Console.WriteLine(snapshot.Uri);
Console.WriteLine(snapshot.SnapshotTime);
}
To reference an existing snapshot, use one of the CloudBlob constructors that takes the snapshot time as a parameter:
static void ReferenceBlobSnapshot(CloudBlobClient blobClient)
{
//Get a reference to a blob.
CloudBlob blob = blobClient.GetBlobReference("mycontainer/myblob.txt");
//Take a snapshot of the blob.
CloudBlob snapshot = blob.CreateSnapshot();
//Get the snapshot timestamp.
DateTime timestamp = (DateTime)snapshot.Attributes.Snapshot;
//Use the timestamp to get a second reference to the snapshot.
CloudBlob snapshot2 = new CloudBlob("mycontainer/myblob.txt", timestamp, blobClient);
//Write out the snapshot URI and timestamp.
Console.WriteLine(snapshot2.Uri);
Console.WriteLine(snapshot2.SnapshotTime);
}