簡體   English   中英

從 azure blob 存儲中獲取文件名

[英]Get file names from azure blob storage

我在 c# 中使用 azure blobstorage,有沒有辦法從給定的特定文件夾中獲取文件列表? 就像在這個 url https://prueba.blob.core.windows.net/simem/UAL/Dato%20de%20archivo%20prueba%20No1/2022/1/16中獲取所有文件名我知道使用 container.GetBlobs()我會得到所有文件,但不是來自特定文件夾

只需使用

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

您可以使用BlobServiceClientGetBlobs並使用 C# 控制台應用程序中的以下代碼從特定文件夾中獲取文件名,我遵循了 Microsoft-Document和@Cindy Pau的回答:

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

在此處輸入圖像描述

pool Container 的 Storage Account 中:

在此處輸入圖像描述

現在里面測試文件夾:

在此處輸入圖像描述

Output:

在每一行之后按 Enter 以逐個獲取文件名。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM