Reputation: 61
So I'm trying to retrieve details of a file I have in blob storage. The idea being that clients ask for documents to be placed on their portal that relate specifically to them.
This is a migration and currently the files are listed in a grid in the format:
File Name, File Size, File Type, Download Link.
The bit I'm having trouble with is retrieving the blob properties.
Here is a code snippet of what I have currently.
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();
}
}
Upvotes: 3
Views: 16038
Reputation: 136386
Try this code. Code assumes that all blobs in your blob container are of type block blobs.
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("=======================================");
}
Upvotes: 15