public void Upload(CloudStorageAccount account, string driveBlobUri) { FileInfo fileInfo = new FileInfo(this.fileName); Console.WriteLine("Uploading virtual hard disk (VHD) file: {0}", fileInfo.Name); Console.WriteLine(); CloudBlobClient blobClient = account.CreateCloudBlobClient(); blobClient.Timeout = new TimeSpan(0, 0, 180); // create page blob to provide backing storage for the drive - pad length to be multiple of 512 bytes CloudPageBlob driveBlob = blobClient.GetPageBlobReference(driveBlobUri); long paddedLength = (fileInfo.Length + PAGEBLOB_PAGE_SIZE - 1) & ~(PAGEBLOB_PAGE_SIZE - 1); Console.WriteLine("Creating Azure Drive"); Console.WriteLine(" URI: {0}", driveBlob.Uri.AbsoluteUri); Console.WriteLine(" Size: {0:n3} MB", paddedLength / (1024 * 1024)); Console.WriteLine(); // first ensure that container exists and then create the blob CloudBlobContainer container = blobClient.GetContainerReference(driveBlob.Container.Name); container.CreateIfNotExist(); driveBlob.Create(paddedLength); this.fileOffset = 0; this.blockLength = 0; Console.WriteLine("{0} - Uploading data...\r\n", DateTime.Now.ToLongTimeString()); using (stream = fileInfo.OpenRead()) { int blockNumber = 0; ProgressIndicator progress = new ProgressIndicator(); while (Read()) { Console.Write("\r Writing block {0,3} at offset: {1,16:n0}, size: {2,16:n1} KB", blockNumber, this.blockOffset, Convert.ToDecimal(this.blockLength) / 1024); progress.Enable(); driveBlob.WritePages(new MemoryStream(this.buffer, 0, this.blockLength, false), this.blockOffset); Console.WriteLine("\r *"); progress.Disable(); blockNumber++; } Console.WriteLine(); Console.WriteLine("{0} - Upload complete.", DateTime.Now.ToLongTimeString()); } }