CloudPageBlob.ClearPages Method (Int64, Int64)

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

Clears pages from a page blob.

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

instance.ClearPages(startOffset, length)

Syntax

Visual Basic
Public Sub ClearPages ( _
	startOffset As Long, _
	length As Long _
)
C#
public void ClearPages (
	long startOffset,
	long length
)
C++
public:
void ClearPages (
	long long startOffset, 
	long long length
)
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.

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.


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