Kulasangar
Kulasangar

Reputation: 9434

Listing the files, which are inside a Blob?

Just started working on with Windows Azure and Mapreduce. I've already created an HDInsight cluster within the Azure Portal and also created a Block Blob using the Azure Explorer named BlobFiles.

What I wanted to know is, is there a way of listing all the files within a Blob which is within a Blob Container? In other words if I'm uploading text files as well as images to the same Blob, how could I list those text files as well as those images programmatically or in another way?

Searched for a solution, but still couldn't come across of one. I'm able to see the content of the file individually using the Azure Explorer, where as um unable to find a way to see or display the files within that particular Blob!

Edited: This is what I've tried to display the Blobs:

        // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference("fyptest1");

        // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

        lboxblob.ItemsSource = container.ListBlobs();//lboxblob is the name of my listbox

When I tried the above code it displays something like Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, and so on for a few number of times.

Any help would be appreciated.

Upvotes: 4

Views: 3671

Answers (2)

Serdar Ozler
Serdar Ozler

Reputation: 3802

That is because the binding would end up calling ToString on every list item returned, which just displays the type name. If you would like to see URIs in your list box instead, please change the last line to:

lboxblob.ItemsSource = container.ListBlobs().Select(b => b.Uri);

But please refer to the other answer for the correct terminology. As others mentioned, blobs do not contain other objects like files.

Upvotes: 3

user189198
user189198

Reputation:

Each Azure storage "blob" is a "file." You want to list the "blobs" in a "blob container," most likely.

To do this, use the CloudBlobContainer.ListBlobs() method.

https://msdn.microsoft.com/en-us/library/azure/dd135734.aspx

Upvotes: 3

Related Questions