我怎么会在根目录下的所有斑点,而不是只有斑点

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

我如何成为从我的Azure存储容器中的所有斑点,而不是只有斑点的根源在哪里?

private CloudBlobContainer GetCloudBlobContainer()
        {

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=*;AccountKey=*;EndpointSuffix=core.windows.net");
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("test123");

            return container;
        }

        public ActionResult ListBlobs()
        {
            CloudBlobContainer container = GetCloudBlobContainer();
            List<string> blobs = new List<string>();
            BlobResultSegment resultSegment = container.ListBlobsSegmentedAsync(null).Result;
            foreach (IListBlobItem item in resultSegment.Results)
            {
                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    CloudBlockBlob blob = (CloudBlockBlob)item;
                    blobs.Add(blob.Name);
                }
                else if (item.GetType() == typeof(CloudPageBlob))
                {
                    CloudPageBlob blob = (CloudPageBlob)item;
                    blobs.Add(blob.Name);
                }
                //Directory
                else if (item.GetType() == typeof(CloudBlobDirectory))
                {
                    CloudBlobDirectory dir = (CloudBlobDirectory)item;
                    blobs.Add(dir.Uri.ToString());
                }
            }

            return View(blobs);
        }

该代码只返回根目录的斑点。但我想也得到一个目录内的斑点。

谢谢

c# asp.net-mvc azure-storage-blobs
1个回答
0
投票

调用useFlatBlobListing方法时请注明ListBlobsSegmentedAsync为true。

© www.soinside.com 2019 - 2024. All rights reserved.