Question

I have an already existing page blob on my Storage Emulator. Now I'm trying to write some more bytes to it using WritePages but it doesn't seem to work. Does Storage Emulator support that or am I doing something wrong maybe?

Here's how I'm trying to do it.

            var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

            var blobClient = account.CreateCloudBlobClient();

            var blobContainer = blobClient.GetContainerReference("mycontainer");
            blobContainer.CreateIfNotExist();
            blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });

            var pageBlob = blobContainer.GetPageBlobReference("filepage.txt");
            pageBlob.FetchAttributes();

            byte[] data = File.ReadAllBytes(@"C:\Temp\moretext.txt");
            Array.Resize(ref data, 512);

            pageBlob.WritePages(new MemoryStream(data), 0);

Thanks

Was it helpful?

Solution

I believe you must have made some mistake either with your blob or your blob may not a be a Page Blob. I just used the following code and verify that WritePage API does work fine on Emulator:

var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var blobClient = account.CreateCloudBlobClient();

var blobContainer = blobClient.GetContainerReference("mycontainer");
blobContainer.CreateIfNotExist();
blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });

// Create a Page Blob
CloudPageBlob pageBlob = blobContainer.GetPageBlobReference("mypageblob");
pageBlob.Create(5120); 
// After above line execution, check Azure Emulated Storage and download the PageBlob locally and verify that it is a 5120 size Page blob

byte[] data = File.ReadAllBytes(@"C:\2012\100text.txt"); // About 300byte text
Array.Resize(ref data, 512);

pageBlob.WritePages(new MemoryStream(data), 0);
// After above line execution, again check Azure Emulated Storage and download the PageBlob locally and verify that it is still a 5120 size Page blob with text in it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top