4

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.

Kulasangar
  • 9,046
  • 5
  • 51
  • 82

2 Answers2

3

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

  • Not the blobs, files within those blobs! – Kulasangar Mar 20 '15 at 14:49
  • 1
    As Trevor said ... each blob is a file. I'm curious to know how you're uploading multiple files to just one blob. – Gaurav Mantri Mar 20 '15 at 14:56
  • @GauravMantri so what you mean is, I could have only one file within a blob? ie: (BlobContainer > Blob > File.txt) I did upload multiple files (not at the same time, one after the other) using the sample given by azure to upload a file. What I meant by multiple files here is that a txt file and an image. So right after I uploaded I did check the content of the blob using Azure Explorer where I found both of them. – Kulasangar Mar 20 '15 at 15:58
  • 3
    `I could have only one file within a blob?` -> That is correct. Again, as Trevor said: Each blob is a file. – Gaurav Mantri Mar 20 '15 at 16:18
  • 2
    Kulasangar, it might help clarify if you pasted some local/remote directory listing. Tell us what files/directories you have locally, and what you have on Storage, and we may be able to help you better. The confusion is likely about terminology - as others have said before, Azure storage doesn't have a concept of files within blobs - each blob is a distinct object. – Atul Sikaria Mar 20 '15 at 17:05
  • I've edited the questions with some code snippets I tried. @AtulSikaria-MSFT – Kulasangar Mar 20 '15 at 18:06
3

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.

Serdar Ozler
  • 3,752
  • 17
  • 24