Home > database >  Get file names from azure blob storage
Get file names from azure blob storage

Time:01-17

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 de archivo prueba No1/2022/1/16 i know that using container.GetBlobs() i would get all files but not from a specific folder

CodePudding user response:

Just use

var results = await container.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.None, null, null, null, null);

CodePudding user response:

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

  • Related