2015-08-19 81 views
1

如何使用C#語言知道Azure中容器的大小。我有幾百TB的文件,所以我不會遞歸地工作。我試着用下面的代碼。如何知道Windows Azure中一個容器的C#大小?

var key = Util.GetPassword("Storage Account Key"); 
var accountName = "mystorageaccount"; 
var connectionString = "DefaultEndpointsProtocol=https;AccountName=" 
         + accountName + ";AccountKey=" + key; 
var account = CloudStorageAccount.Parse(connectionString); 
var blobClient = account.CreateCloudBlobClient(); 
var blobContainer = blobClient.GetContainerReference("mycontainer"); 
long fileSize = 0; 
foreach (CloudBlockBlob blobItem in blobContainer.ListBlobs()) 
{ 
    fileSize += blobItem.Properties.Length; 
} 
fileSize.Dump(); 

回答

1

這裏是你正在尋找...

 string key = ""; 
     string accountName = "mystorageaccount"; 
     string connectionString = "DefaultEndpointsProtocol=https;AccountName=" 
           + accountName + ";AccountKey=" + key; 
     var account = CloudStorageAccount.Parse(connectionString); 
     var blobClient = account.CreateCloudBlobClient(); 
     var blobContainer = blobClient.GetContainerReference("mycontainer"); 
     long fileSize = 0; 
     foreach(CloudBlobContainer container in blobClient.ListContainers()) 
     { 
      fileSize += (from ICloudBlob blob in 
          container.ListBlobs(useFlatBlobListing: true) 
          select blob.Properties.Length).Sum(); 
     } 
+0

剛一說明,如果斑點數很高,最好是使用BlobContinuationToken實現分頁代碼。否則上面的代碼將超時。 – Hanno

相關問題