简体   繁体   English

如何使用 c# 获取 Azure 容器虚拟文件夹中的文件

[英]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.

相关问题 在 azure 上的虚拟文件夹中获取 blob (BlobService.ListBlobs) (C#) - Get blobs in a virtual folder on azure (BlobService.ListBlobs) (C#) 使用 C# 从 Azure DataLake 获取所有文件夹中所有文件的列表 - Get List of all files from all folder from Azure DataLake using C# 如何使用C#获取Azure中的虚拟机列表? - How to get a list of virtual machines in Azure with c#? 如何使用C#从Azure容器/ Blob中读取/下载所有文件? - How to read/Download all files from a Azure container/Blob using C#? 使用 C# 获取存储在 azure 容器中的音频 blob 的持续时间 - Get the duration of audio blob stored in azure container using C# 如何使用 c# 获取 Azure Blob 存储容器中现有目录的列表? - How to get a list of existing directories in Azure Blob Storage container using c#? Azure Data Lake Gen2 - 如何使用 C# 将文件从文件夹移动到另一个文件夹 - Azure Data Lake Gen2 - How do I move files from folder to another folder using C# 如何使用C#文件移动到虚拟目录 - How to move files to a virtual directory using c# 如何使用 c# 从 UWP 中的文件夹“C:\\Test”中获取所有文本文件? - How to get all text files from a folder "C:\Test" in UWP using c#? 如何在 Azure Function C# 中获取文件夹的路径 - How to get the path of folder in Azure Function C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM