gpt4 book ai didi

c# - 列出 Windows Azure Blob 存储容器中的目录

转载 作者:可可西里 更新时间:2023-11-01 07:44:34 30 4
gpt4 key购买 nike

我对我的项目有疑问...我需要知道如何列出 Windows Azure blob 存储中的所有文件夹(以字符串列表或其他形式)...我已经准备好 BlobClient 以及与 Azure 的连接存储。

谁能帮我解决这个“问题”?

最佳答案

试试这个代码。它使用存储客户端库2.0.3:

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("wad-control-container");
string blobPrefix = null;
bool useFlatBlobListing = false;
var blobs = blobContainer.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None);
var folders = blobs.Where(b => b as CloudBlobDirectory != null).ToList();
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}

如果您使用存储客户端库 1.8(即 2.0 之前的版本),请尝试以下代码:

        var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference("wad-control-container");
IEnumerable<IListBlobItem> blobs = container.ListBlobs(new BlobRequestOptions()
{
UseFlatBlobListing = false,
});
var folders = blobs.Where(b => b as CloudBlobDirectory != null);

foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}

关于c# - 列出 Windows Azure Blob 存储容器中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14503772/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com