所以我试图检索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 :(得分:11)
试试这段代码。代码假定blob容器中的所有blob都是块blob类型。
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("=======================================");
}
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("=======================================");
}