如何列出目录Azure中包含的Blob

时间:2018-11-13 11:20:35

标签: c# azure-storage-blobs virtual-directory

因此,我试图列出虚拟文件夹中包含的Blob,我们将其称为“ VF”

我尝试了很多方法,例如:

If(listaMetodo[iExample].ControlName.equals(validateList[jExample].NameOfControl && validateList[jExample].Valida){

//here I should get the instance of the object by reflection and change ._ValidaMsg and ._Valida

}

但是我收到如下错误:

var storageAccount = CloudStorageAccount.Parse("...");

var blobClient = storageAccount.CreateCloudBlobClient();

var container = blobClient.GetContainerReference("Container_Name");

List<IListBlobItem> blobslist = container.ListBlobsSegmentedAsync("VF", true).ToList();

我正在尝试使用API​​返回文件内容,这就是为什么我遇到麻烦并使用错误的方法吗?

非常感谢您的帮助

1 个答案:

答案 0 :(得分:2)

您需要正确实现BlobContinuationToken的用法。

尝试一下

if (CloudStorageAccount.TryParse(connectionString, out CloudStorageAccount storageAccount))
{
    var context = new OperationContext();
    var options = new BlobRequestOptions();
    var cloudBlobClient = storageAccount.CreateCloudBlobClient();
    var cloudBlobContainer = cloudBlobClient.GetContainerReference(blobContainerName);
    BlobContinuationToken blobContinuationToken = null;
    do
    {
        var results = await cloudBlobContainer.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All,
            null, blobContinuationToken, options, context);
        blobContinuationToken = results.ContinuationToken;
        foreach (var item in results.Results)
        {
            //do what you want with each blob
        }
    } while (blobContinuationToken != null);
}