简体   繁体   中英

Get file names from azure blob storage

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

Just use

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

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();
            }    
        }
    }
}

在此处输入图像描述

In Storage Account of pool Container:

在此处输入图像描述

Now inside test Folder:

在此处输入图像描述

Output:

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM