2013-02-15 38 views
2

所以我試圖檢索我在BLOB存儲文件的詳細信息。這個想法是,客戶要求將文檔放在他們的門戶上,這些文檔專門與他們相關。檢索一個BLOB文件名

這是一個移民和當前的文件在格式網格上市:

文件名,文件大小,文件類型,下載鏈接。

我遇到的問題是檢索blob屬性。

這是我目前所擁有的代碼片段。

public void BindGridDocuments() 
{ 
    var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString); 
    var blobStorage = storageAccount.CreateCloudBlobClient(); 
    CloudBlobContainer container = blobStorage.GetContainerReference("documents"); 
    var documentCollection = container.ListBlobs(); 
    foreach (var document in documentCollection) 
    { 
     string filename = document.Uri.ToString(); 

    } 
} 
+0

的document.Uri應包含文件名。你需要將其去掉。 – tomasmcguinness 2013-02-15 13:14:41

+0

你到底需要檢索什麼? – 2013-02-15 13:15:35

+0

我猜我可以從uri中提取文件名。如果可能的話,我也喜歡文件大小。 – 2013-02-15 13:22:48

回答

10

試試看看這個代碼。代碼假定您的blob容器中的所有Blob都是類型塊blob。

存儲客戶端庫2.0:

 CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 
     CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("images"); 
     var blobs = blobContainer.ListBlobs(null, true, BlobListingDetails.All).Cast<CloudBlockBlob>(); 
     foreach (var blockBlob in blobs) 
     { 
      Console.WriteLine("Name: " + blockBlob.Name); 
      Console.WriteLine("Size: " + blockBlob.Properties.Length); 
      Console.WriteLine("Content type: " + blockBlob.Properties.ContentType); 
      Console.WriteLine("Download location: " + blockBlob.Uri); 
      Console.WriteLine("======================================="); 
     } 

存儲客戶端庫1.7:

 CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 
     CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("images"); 
     var blobs = blobContainer.ListBlobs(new BlobRequestOptions() 
      { 
       BlobListingDetails = BlobListingDetails.All, 
       UseFlatBlobListing = true, 
      }).Cast<CloudBlockBlob>(); 
     foreach (var blockBlob in blobs) 
     { 
      Console.WriteLine("Name: " + blockBlob.Name); 
      Console.WriteLine("Size: " + blockBlob.Properties.Length); 
      Console.WriteLine("Content type: " + blockBlob.Properties.ContentType); 
      Console.WriteLine("Download location: " + blockBlob.Uri); 
      Console.WriteLine("======================================="); 
     } 
+0

謝謝。這似乎完成了這項工作。 – 2013-02-15 15:29:50

+0

現在輕微的問題傢伙在下載位置返回此錯誤消息: – 2013-02-18 15:44:20

+0

你收到的錯誤信息是什麼? – 2013-02-20 14:57:48