public async Task PageBlobSample() { // Instantiate a new BlobServiceClient using a connection string. BlobServiceClient blobServiceClient = new BlobServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString); // Instantiate a new BlobContainerClient BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient($"mycontainer3-{Guid.NewGuid()}"); try { // Create new Container in the Service await blobContainerClient.CreateAsync(); // Instantiate a new PageBlobClient PageBlobClient pageBlobClient = blobContainerClient.GetPageBlobClient("pageblob"); // Create PageBlob in the Service const int blobSize = 1024; await pageBlobClient.CreateAsync(size : blobSize); // Upload content to PageBlob using (FileStream fileStream = File.OpenRead("Samples/SampleSource.txt")) { // Because the file size varies slightly across platforms // and PageBlob pages need to be multiples of 512, we'll // pad the file to our blobSize using (MemoryStream pageStream = new MemoryStream(new byte[blobSize])) { await fileStream.CopyToAsync(pageStream); pageStream.Seek(0, SeekOrigin.Begin); await pageBlobClient.UploadPagesAsync( content : pageStream, offset : 0); } } // Download PageBlob using (FileStream fileStream = File.Create("PageDestination.txt")) { Response <BlobDownloadInfo> downloadResponse = await pageBlobClient.DownloadAsync(); await downloadResponse.Value.Content.CopyToAsync(fileStream); } // Delete PageBlob in the Service await pageBlobClient.DeleteAsync(); } finally { // Delete Container in the Service await blobContainerClient.DeleteAsync(); } }
public async Task PageBlobSample() { // Instantiate a new BlobServiceClient using a connection string. BlobServiceClient blobServiceClient = new BlobServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString); // Instantiate a new BlobContainerClient BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient("mycontainer3"); try { // Create new Container in the Service await blobContainerClient.CreateAsync(); // Instantiate a new PageBlobClient PageBlobClient pageBlobClient = blobContainerClient.GetPageBlobClient("pageblob"); // Create PageBlob in the Service await pageBlobClient.CreateAsync(size : 1024); // Upload content to PageBlob using (FileStream fileStream = File.OpenRead("Samples/SampleSource.txt")) { await pageBlobClient.UploadPagesAsync( content : fileStream, offset : 0); } // Download PageBlob using (FileStream fileStream = File.Create("PageDestination.txt")) { Response <BlobDownloadInfo> downloadResponse = await pageBlobClient.DownloadAsync(); await downloadResponse.Value.Content.CopyToAsync(fileStream); } // Delete PageBlob in the Service await pageBlobClient.DeleteAsync(); } finally { // Delete Container in the Service await blobContainerClient.DeleteAsync(); } }