如何使用C#语言了解azure中容器的大小。我有数百TB的文件,所以我不会递归地工作。我尝试使用以下代码。
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();
答案 0 :(得分: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();
}