c# - 从 azure blob 存储获取文件名

标签 c# azure directory azure-blob-storage blob

我在 C# 中使用 azure blobstorage,有没有办法从给定的特定文件夹中获取文件列表? 就像获取此 url https://prueba.blob.core.windows.net/simem/UAL/Dato%20de%20archivo%20prueba%20No1/2022/1/16 内的所有文件名 我知道使用 container.GetBlobs() 我会获取所有文件,但不会从特定文件夹获取

最佳答案

您可以使用 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();
            }    
        }
    }
}

enter image description here

容器的存储帐户中:

enter image description here

现在在test文件夹中:

enter image description here

输出:

每行后按 Enter 键即可一一获取文件名。

enter image description here

关于c# - 从 azure blob 存储获取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75134634/

相关文章:

c# - 您如何平衡框架/API 设计和 TDD

c# - 在 Silverlight 中如何确定是否是用户更改了 ComboBox?

Azure:无法安装正确推送到工件源存储库的 PowerShell 模块

c# - 我的 web api 仅从 ajax 客户端给出 net::ERR_CONNECTION_RESET 错误

python - 如何在 Python 中访问我的 iPhone 文件(通过 USB)?

git - 如何从 Git 存储库中提取任何提交到文件夹/存档的所有文件?

c# - 找不到引用组件

c# - Xamarin.forms 自定义字体异常

azure - 创建 Azure 表存储文件夹

Python:将目录结构树表示为列表的列表