且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用c#获取Azure Blob存储容器中的现有目录列表?

更新时间:2023-02-09 10:00:39

也许您可以通过检查blob项的类型来改进您的解决方案?

Maybe you can improve your solution doing a check for the type of blob item?

        var result = new List<string>();
        var directory = _blobContainer.GetDirectoryReference(relativeFilePath);

        if (directory.Equals(null))
            return result;

        var blobs = directory.ListBlobsSegmentedAsync(null).Result;

        foreach (var item in blobs.Results)
        {
            if (item.GetType() == typeof(CloudBlobDirectory)) 
            {
                result.Add(item.Uri.Segments.Last().Trim('/'));
            }
        }

        return result;

我没有太多文件夹,所以***再次检查一下性能是否符合您的要求.

I didn't have too many folders so would be good to double check if the performance meets your requirements.