C# 如何在CloudBlobContainer.ListBlobs()中使用prefix参数从Azure blob存储中的虚拟文件夹获取文件

C# 如何在CloudBlobContainer.ListBlobs()中使用prefix参数从Azure blob存储中的虚拟文件夹获取文件,c#,azure,azure-storage,azure-storage-blobs,C#,Azure,Azure Storage,Azure Storage Blobs,我正在尝试在Azure blob存储中的单个虚拟文件夹中获取列表。这些文件以/{container}/{classification}/{title}文件夹结构组织,所有文件都位于“title”虚拟文件夹中 这是我使用的函数,它不使用前缀,但在提供前缀时无法返回任何结果 public static List<string> List(string classification, string title, StorageAccount sa) { List<string

我正在尝试在Azure blob存储中的单个虚拟文件夹中获取列表。这些文件以/{container}/{classification}/{title}文件夹结构组织,所有文件都位于“title”虚拟文件夹中

这是我使用的函数,它不使用前缀,但在提供前缀时无法返回任何结果

public static List<string> List(string classification, string title, StorageAccount sa)
{
    List<string> fileList = new List<string>();
    CloudBlobContainer container = GetBlobContainer(sa);
    var prefix = $"/{container.Name}/{classification}/{title}/";
    Console.WriteLine(prefix);

    var list = container.ListBlobs(prefix, useFlatBlobListing: true);

    foreach (var blob in list)
    {
        var blobFileName = blob.Uri.AbsolutePath;
        fileList.Add(blobFileName);
    }

    return fileList;
}
公共静态列表(字符串分类、字符串标题、StorageAccount sa)
{
List fileList=新列表();
CloudBlobContainer容器=GetBlobContainer(sa);
var前缀=$“/{container.Name}/{classification}/{title}/”;
Console.WriteLine(前缀);
var list=container.ListBlobs(前缀,useFlatBlobListing:true);
foreach(列表中的var blob)
{
var blobFileName=blob.Uri.AbsolutePath;
fileList.Add(blobFileName);
}
返回文件列表;
}

您不需要在前缀中包含容器名称。请更改以下代码行:

var prefix = $"/{container.Name}/{classification}/{title}/";
致:


这将列出所有以该前缀开头的blob名称。

前缀中可以包含的级别数量是否有限制?如果我用两个“文件夹”级别作为前缀,它就会工作。如果我使用三个级别作为前缀,它将不返回任何内容。我正在将useFlatBlobListing设置为true。@Molotch我认为没有任何限制。我建议发布另一个包含所有相关细节的问题。
var prefix = $"{classification}/{title}/";