我在 C# 中使用 azure blobstorage,有没有办法从给定的特定文件夹中获取文件列表? 就像获取此 url https://prueba.blob.core.windows.net/simem/UAL/Dato%20de%20archivo%20prueba%20No1/2022/1/16 内的所有文件名 我知道使用 container.GetBlobs() 我会获取所有文件,但不会从特定文件夹获取
最佳答案
您可以使用 BlobServiceClient
和 GetBlobs
从特定文件夹获取文件名,并在 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();
}
}
}
}
在池容器的存储帐户中:
现在在test文件夹中:
输出:
每行后按 Enter 键即可一一获取文件名。
关于c# - 从 azure blob 存储获取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75134634/