2017-04-04 5 views
0

VHDを自分のリソースグループのストレージアカウントにコピーする方法を探しています。VHDL/BLOBをコピーするAzure Resource Manager .NET SDK

私はVHDのSas Uriを持っています。

I PowerShellは、私が使用します。

Start-AzureStorageBlobCopy ` 
-AbsoluteUri $sas.AccessSAS ` 
-DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd' 

はそれを行うために。

Azure Resource Managerの.NET SDKからやり方を見つけることができないようです。 https://github.com/Azure/azure-sdk-for-net/tree/AutoRest/src/ResourceManagement/

.NETを使用してBLOBをコピーする方法はありますか。

答えて

1

.NETを使用してBLOBをコピーする方法はありますか。

あなたはAzure Storage SDK for .NetGithub | Nuget)を使用する必要があります。

using Microsoft.WindowsAzure.Storage; 
using Microsoft.WindowsAzure.Storage.Auth; 
using Microsoft.WindowsAzure.Storage.Blob; 

    static void CopyBlobUsingSasExample() 
    { 
     var destinationAccountName = ""; 
     var destinationAccountKey = ""; 
     var destinationAccount = new CloudStorageAccount(new StorageCredentials(destinationAccountName, destinationAccountKey), true); 
     var destinationContainerName = "vhds"; 
     var destinationContainer = destinationAccount.CreateCloudBlobClient().GetContainerReference(destinationContainerName); 
     destinationContainer.CreateIfNotExists(); 
     var destinationBlob = destinationContainer.GetPageBlobReference("MyDestinationBlobName.vhd"); 
     var sourceBlobSasUri = ""; 
     destinationBlob.StartCopy(new Uri(sourceBlobSasUri)); 
     //Since copy operation is async, please wait for the copy operation to finish. 
     do 
     { 
      destinationBlob.FetchAttributes(); 
      var copyStatus = destinationBlob.CopyState.Status; 
      if (copyStatus != CopyStatus.Pending) 
      { 
       break; 
      } 
      else 
      { 
       System.Threading.Thread.Sleep(5000);//Sleep for 5 seconds and then fetch attributes to check the copy status. 
      } 
     } while (true); 
    } 
関連する問題