skip to Main Content

I’m using azure blobstorage in c#, is there a way, a method to get the list of files from a given specific folder?
like get all file names inside this url https://prueba.blob.core.windows.net/simem/UAL/Dato%20de%20archivo%20prueba%20No1/2022/1/16
i know that using container.GetBlobs() i would get all files but not from a specific folder

2

Answers


  1. Just use

    var results = await container.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.None, null, null, null, null);
    
    Login or Signup to reply.
  2. You can get file names from a specific folder using BlobServiceClient and GetBlobs and by using below code in C# Console App and I followed Microsoft-Document and @Cindy Pau‘s answer:

    using Azure.Storage.Blobs;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp4
    {
        class Program
        {
            static void Main(string[] args)
            {
                string cs= "Connection String of Storage Account";
                string f = "test";
                BlobServiceClient b = new BlobServiceClient(cs);
                string c = "pool";
                BlobContainerClient containerClient =b.GetBlobContainerClient(c);
                var bs= containerClient.GetBlobs(prefix: f);
                foreach (var x in bs)
                {
                    Console.WriteLine(x.Name);
                    Console.ReadLine();
                }    
            }
        }
    }
    

    enter image description here

    In Storage Account of pool Container:

    enter image description here

    Now inside test Folder:

    enter image description here

    Output:

    Press Enter after every line to get File names one by one.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search