匯出 (0) 列印
全部展開

CloudDrive.Create 方法

Creates a single-partition, NTFS-formatted Virtual Hard Disk (VHD) page blob to back the Windows Azure drive.

命名空間: Microsoft.WindowsAzure.StorageClient
組件: Microsoft.WindowsAzure.CloudDrive (在 microsoft.windowsazure.clouddrive.dll 中)

'用途
Dim instance As CloudDrive
Dim sizeInMB As Integer

instance.Create(sizeInMB)

public void Create (
	int sizeInMB
)
public void Create (
	int sizeInMB
)
public function Create (
	sizeInMB : int
)

參數

sizeInMB

The size of the drive to create. The minimum size permitted is 16 MB. The maximum size permitted is 1 TB (the maximum size permitted for a page blob).

The following example creates and mounts a Windows Azure drive.


public void CreateAndMountDrive()
{
    // 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 64 MB drive.
        drive.Create(64);

        // 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");
        }
    }
    catch (CloudDriveException e)
    {
        System.Diagnostics.Debug.WriteLine(e.Message);
    }
}

The Create method creates a page blob at the location specified when the reference to the CloudDrive object was created. The container for the page blob must exist before you call the Create method.

note注意事項
If the blob exists, the Create method will fail with a CloudDriveException. To prevent your role from recycling, ensure that you handle this exception properly and do not create a drive that already exists.

To mount a drive using an existing blob or snapshot, create a reference to a CloudDrive object using the URI to the existing blob, then call the Mount method without calling Create.

The Windows Azure drive is created as a fixed VHD within the page blob. Note that the drive format requires some space, so you will not have access to the full amount of space that you allocate for the drive.

note注意事項
The Windows Azure development environment provides a simulation of a Windows Azure drive which does not rely on the Windows Azure storage emulator. If your code is running in the development environment, you will not see an actual page blob created in the local Blob service.


任何這個類型的公用靜態 (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。 並非所有的執行個體成員都是安全執行緒。

開發平台

Windows XP Home Edition, Windows XP Professional, Windows Server 2003、Windows Server 2008 和 Windows 2000

目標平台

社群新增項目

顯示:
© 2014 Microsoft