0

I have some .png files inside a Blob Container, I'm able to retrieve a file by passing the filename as a parameter :

var blob = container.GetBlockBlobReference(System.IO.Path.GetFileName(fileName));

But I want to query that Blob Container and have a list of all the files that it contains. How would I do that?

 public class FilesController : Controller
    {
        private CloudBlobContainer container;
        private CloudStorageAccount storageAccount;
        private CloudBlobClient blobClient;
        private CloudTableClient tableClient;
 public FilesController()
        {
            this.storageAccount = CloudStorageAccount.Parse(_dbConnection.ConnectionAzure);
            this.storageAccount.CreateCloudBlobClient();
            this.blobClient = storageAccount.CreateCloudBlobClient();
            this.container = blobClient.GetContainerReference("public/MyFolder");
            this.tableClient = storageAccount.CreateCloudTableClient();
        }

public ActionResult MyMethod(string fileName)
        {
           var blob = container.GetBlockBlobReference(System.IO.Path.GetFileName(fileName));
        }
AlexGH
  • 2,735
  • 5
  • 43
  • 76

1 Answers1

2

How about this:

var list = container.ListBlobs(useFlatBlobListing: true);
var listOfFileNames = new List<string>();

foreach (var blob in blobs) {
  var blobFileName = blob.Uri.Segments.Last();
  listOfFileNames.Add(blobFileName); 
}

return listOfFileNames;

Source: Getting list of names of Azure blob files in a container?

Community
  • 1
  • 1
degant
  • 4,861
  • 1
  • 17
  • 29