Clears pages from a page blob, using a conditional request based on the BlobRequestOptions specified. Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Usage
Visual Basic |
---|
Dim instance As CloudPageBlob Dim startOffset As Long Dim length As Long Dim options As BlobRequestOptions instance.ClearPages(startOffset, length, options) |
Syntax
Visual Basic |
---|
Public Sub ClearPages ( _ startOffset As Long, _ length As Long, _ options As BlobRequestOptions _ ) |
C# |
---|
public void ClearPages ( long startOffset, long length, BlobRequestOptions options ) |
C++ |
---|
public: void ClearPages ( long long startOffset, long long length, BlobRequestOptions^ options ) |
J# |
---|
JScript |
---|
Parameters
- startOffset
Type: System.Int64
The offset at which to begin clearing pages, in bytes. The offset must be a multiple of 512.
- length
Type: System.Int64
The length of the data range to be cleared, in bytes. The length must be a multiple of 512.
- options
Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions
An object that specifies any additional options for the request.
Example
The following code example creates a page blob, writes some pages to it, clears a page, and prints out the page ranges to the console.
C# | Copy Code |
---|---|
static void WriteToPageBlob(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)); // create container if it does not exist CloudBlobContainer cloudContainer = blobClient.GetContainerReference("mypageblobs"); cloudContainer.CreateIfNotExist(); //Get a reference to the page blob that will be created. CloudPageBlob pageBlob = cloudContainer.GetPageBlobReference("apageblob"); //Generate some data to write. byte[] data = new byte[1024]; Random rnd = new Random(); rnd.NextBytes(data); //Create a 100 MB page blob. pageBlob.Create(100 * 1024 * 1024); //Write two sets of pages. Note that you can write 4 MB per call to WritePages(). pageBlob.WritePages(new MemoryStream(data), 0); pageBlob.WritePages(new MemoryStream(data), 4096); //Populate the page blob's attributes. pageBlob.FetchAttributes(); Console.WriteLine("Blob length = {0}", pageBlob.Properties.Length); //Print out the current range of pages. PrintPageRanges("Before write to 10240:", pageBlob); //Write another page. pageBlob.WritePages(new MemoryStream(data), 10240); //Print out the new range of pages. PrintPageRanges("After write to 10240:", pageBlob); //Clear a page. pageBlob.ClearPages(4096, 1024); //Print out the new range of pages. PrintPageRanges("After clearing page at 4096:", pageBlob); //Delete the page blob. pageBlob.Delete(); } static void PrintPageRanges(string msg, CloudPageBlob cloudBlob) { //Write out the page ranges for the page blob. IEnumerable<PageRange> ranges = cloudBlob.GetPageRanges(); Console.Write("{0}:<", msg); foreach (PageRange range in ranges) { Console.Write(" [{0}-{1}] ", range.StartOffset, range.EndOffset); } Console.WriteLine(">"); } |
Remarks
Calling ClearPages releases the storage space used by the specified page. Pages that have been cleared are no longer tracked as part of the page blob.
Pages that have been cleared no longer incur a charge against the storage account, as their storage resources have been released.