Proposed Pull Request Change

title titleSuffix description services author ms.author ms.service ms.topic ms.date ms.devlang ms.custom
List blob containers with .NET Azure Storage Learn how to list blob containers in your Azure Storage account using the .NET client library. storage stevenmatthew shaas azure-blob-storage how-to 08/05/2024 csharp devx-track-csharp, devguide-csharp, devx-track-dotnet
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
Content Truncation Detected
The generated rewrite appears to be incomplete.
Original lines: -
Output lines: -
Ratio: -
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: List blob containers with .NET titleSuffix: Azure Storage description: Learn how to list blob containers in your Azure Storage account using the .NET client library. services: storage author: stevenmatthew ms.author: shaas ms.service: azure-blob-storage ms.topic: how-to ms.date: 08/05/2024 ms.devlang: csharp ms.custom: devx-track-csharp, devguide-csharp, devx-track-dotnet # Customer intent: "As a .NET developer, I want to list blob containers in my Azure Storage account, so that I can manage and retrieve container information efficiently based on specific options like prefixes and pagination." --- # List blob containers with .NET [!INCLUDE [storage-dev-guide-selector-list-container](../../../includes/storage-dev-guides/storage-dev-guide-selector-list-container.md)] When you list the containers in an Azure Storage account from your code, you can specify a number of options to manage how results are returned from Azure Storage. This article shows how to list containers using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage). [!INCLUDE [storage-dev-guide-prereqs-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-dotnet.md)] ## Set up your environment [!INCLUDE [storage-dev-guide-project-setup-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-dotnet.md)] #### Authorization The authorization mechanism must have the necessary permissions to list blob containers. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Contributor** or higher. To learn more, see the authorization guidance for [List Containers (REST API)](/rest/api/storageservices/list-containers2#authorization). ## About container listing options When listing containers from your code, you can specify options to manage how results are returned from Azure Storage. You can specify the number of results to return in each set of results, and then retrieve the subsequent sets. You can also filter the results by a prefix, and return container metadata with the results. These options are described in the following sections. To list containers in your storage account, call one of the following methods: - [GetBlobContainers](/dotnet/api/azure.storage.blobs.blobserviceclient.getblobcontainers) - [GetBlobContainersAsync](/dotnet/api/azure.storage.blobs.blobserviceclient.getblobcontainersasync) These methods return a list of [BlobContainerItem](/dotnet/api/azure.storage.blobs.models.blobcontaineritem) objects. Containers are ordered lexicographically by name. ### Manage how many results are returned By default, a listing operation returns up to 5000 results at a time, but you can specify the number of results that you want each listing operation to return. The examples presented in this article show you how to return results in pages. To learn more about pagination concepts, see [Pagination with the Azure SDK for .NET](/dotnet/azure/sdk/pagination). ### Filter results with a prefix To filter the list of containers, specify a string for the `prefix` parameter. The prefix string can include one or more characters. Azure Storage then returns only the containers whose names start with that prefix. ### Include container metadata To include container metadata with the results, specify the `Metadata` value for the [BlobContainerTraits](/dotnet/api/azure.storage.blobs.models.blobcontainertraits) enum. Azure Storage includes metadata with each container returned, so you don't need to fetch the container metadata separately. ### Include deleted containers To include soft-deleted containers with the results, specify the `Deleted` value for the [BlobContainerStates](/dotnet/api/azure.storage.blobs.models.blobcontainerstates) enum. ## Code example: List containers The following example asynchronously lists the containers in a storage account that begin with a specified prefix. The example lists containers that begin with the specified prefix and returns the specified number of results per call to the listing operation. It then uses the continuation token to get the next segment of results. The example also returns container metadata with the results. :::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/dotnet-v12/Containers.cs" id="Snippet_ListContainers"::: ## Resources To learn more about listing containers using the Azure Blob Storage client library for .NET, see the following resources. ### REST API operations The Azure SDK for .NET contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar .NET paradigms. The client library methods for listing containers use the following REST API operation: - [List Containers](/rest/api/storageservices/list-containers2) (REST API) [!INCLUDE [storage-dev-guide-resources-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-resources-dotnet.md)] ### See also - [Enumerating Blob Resources](/rest/api/storageservices/enumerating-blob-resources) [!INCLUDE [storage-dev-guide-next-steps-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-next-steps-dotnet.md)]
Success! Branch created successfully. Create Pull Request on GitHub
Error: