CloudDrive.Delete Method
Deletes the page blob associated with this Windows Azure drive and all data that it contains.
Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.CloudDrive (in Microsoft.WindowsAzure.CloudDrive.dll)
Assembly: Microsoft.WindowsAzure.CloudDrive (in Microsoft.WindowsAzure.CloudDrive.dll)
The following example creates and mounts a Windows Azure drive, writes some files to it, then unmounts and deletes the drive.
public void UnmountAndDeleteDrive() { // Use the storage emulator. CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; // Create the Blob service client. CloudBlobClient client = storageAccount.CreateCloudBlobClient(); // Create the container for the drive if it does not already exist. CloudBlobContainer container = new CloudBlobContainer("mydrives", client); container.CreateIfNotExist(); // Get a reference to the page blob that will back the drive. CloudPageBlob pageBlob = container.GetPageBlobReference("myvhd"); // Return a reference to the drive backed by the specified page blob. CloudDrive drive = new CloudDrive(pageBlob.Uri, storageAccount.Credentials); try { // Create a 20 MB drive. drive.Create(20); // Mount the drive. string driveLetter = drive.Mount(0, DriveMountOptions.None); // Write some files to the drive. for (int i = 0; i < 1000; i++) { System.IO.File.WriteAllText(driveLetter + "\\" + i.ToString() + ".txt", "Test"); } // Write out a file's length. FileInfo file = new FileInfo(driveLetter + "\\0.txt"); System.Diagnostics.Debug.WriteLine(file.Length); // Unmount the drive. drive.Unmount(); // Delete the drive. drive.Delete(); } catch (CloudDriveException e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
Note |
|---|
| When defining the connection string for connecting to the storage account, you must use the HTTP protocol. The HTTPS protocol is not supported for creating a drive. |
Before you can delete a drive, you must call Unmount to unmount the drive. Attempting to delete the drive without unmounting it results in a CloudDriveException.
If the page blob backing the drive has associated snapshots, you must delete the snapshots before deleting the drive. To delete snapshots, call the Delete, making sure to set the DeleteSnapshotsOption on the request.
Caution |
|---|
| Use the Delete method with caution, as calling it will delete the data in your drive irretrievably. |
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Development Platforms
Windows Vista, Windows 7 and Windows Server 2008Target Platforms
Note
Caution