Getting list of names of Azure blob files in a container?

前端 未结 8 1631
醉酒成梦
醉酒成梦 2020-12-15 15:31

I need to list names of Azure Blob file names. Currently I m able to list all files with URL but I just need list of names. I want to avoid parsing names. Can you please see

相关标签:
8条回答
  • 2020-12-15 16:19

    We can get some additional info like Size, Modified date and Name.

    CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(YOUR_CON_STRING);
    
    var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
    var backupContainer = backupBlobClient.GetContainerReference("CONTAINER");
    
    
    var blobs = backupContainer.ListBlobs().OfType<CloudBlockBlob>().ToList();
    
    foreach (var blob in blobs)
    {
        string bName = blob.Name;
        long bSize = blob.Properties.Length;
        string bModifiedOn = blob.Properties.LastModified.ToString();        
    }
    

    Also you can download a specific file by Name.

     // Download file by Name
     string fileName = "Your_file_name";
     CloudBlockBlob blobFile = backupContainer.GetBlockBlobReference(fileName);
     blobFile.DownloadToFile(@"d:\"+ fileName, System.IO.FileMode.Create);
    
    0 讨论(0)
  • 2020-12-15 16:27

    You can access the BlobProperties to get the name:

    foreach (object o in list)
    {
        BlobProperties bp = o as BlobProperties;
        if (bp != null)
        {
            BlobProperties p = _Container.GetBlobProperties(bp.Name);
            var name = p.Name; // get the name
        }
    }
    
    0 讨论(0)
提交回复
热议问题