如何检查Azure Blob存储V12中是否存在容器

问题描述 投票:0回答:1

以前使用Azure Blob存储SDK V11时,如果要创建容器,但不确定该容器是否存在,则可以使用CreateIfNotExists。

但是在V12版本中,CreateIfNotExists不再可用,我可以从Microsoft找到的唯一示例是简单地创建一个Container而不检查它是否已经存在。

因此,有人知道V12中的最佳做法是在尝试创建容器之前先检查是否存在容器。

顺便说一句,我正在为ASP.Net Core 3.1开发。

azure asp.net-core azure-storage azure-storage-blobs azure-blob-storage
1个回答
0
投票

在v12中,您应该创建一个容器客户端,然后使用下面的代码:

            BlobContainerClient blobContainer = new BlobContainerClient(connectionString, "the container name");

            //use code below
            blobContainer.Exists();

            //or use this code
            blobContainer.CreateIfNotExists();
© www.soinside.com 2019 - 2024. All rights reserved.