[英]How to get the files in an Azure container virtual folder using c#
I've reviewed this: Getting list of names of Azure blob files in a container?我已经查看过: 获取容器中 Azure blob 文件的名称列表?
and this: https://feedback.azure.com/forums/287593-logic-apps/suggestions/16252474-list-files-in-folder-on-azure-blob-storage和这个: https : //feedback.azure.com/forums/287593-logic-apps/suggestions/16252474-list-files-in-folder-on-azure-blob-storage
But I have not found any code examples of how to list the files in a particular virtual folder within a container using c#.但是我还没有找到任何关于如何使用 c# 列出容器内特定虚拟文件夹中的文件的代码示例。 This is as far as I got.
这是我得到的。 I do not see any way to specify a file path in the ListBlobs ()method.
我没有看到在 ListBlobs () 方法中指定文件路径的任何方法。
var blobStorageAccount = GetStorageAccount();
var blobClient = blobStorageAccount.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(containerName);
List<string> blobNames = blobContainer.ListBlobs().OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
There is no such thing as a subfolder.没有子文件夹这样的东西。 You have containers containing blobs.
您有包含 blob 的容器。 You do have virtual folders, for example
例如,您确实有虚拟文件夹
/container/virtualfolder/myblob
The container name is container
and the blob name is virtualfolder/myblob
容器名称为
container
,blob 名称为virtualfolder/myblob
You can list all blobs in a virtual folder using the prefix
parameter (see the docs ):您可以使用
prefix
参数列出虚拟文件夹中的所有 blob(请参阅文档):
var blobStorageAccount = GetStorageAccount();
var blobClient = blobStorageAccount.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(containerName);
List<string> blobNames = blobContainer.ListBlobs(prefix: "virtualfolder").OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
Microsoft.Azure.Storage.Blob
is deprecated. Microsoft.Azure.Storage.Blob
已弃用。 Using Azure.Storage.Blob
looks like it would be:使用
Azure.Storage.Blob
看起来像这样:
List<string> blobNames = blobContainer.GetBlobs(prefix: "virtualfolder").Select(b => b.Name).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.