如何使用C#从Azure存储下载所有文件?

时间:2022-03-24 03:47:01

I am new bee to Azure Storage. So, please consider my content in post. I have a Azure Storage account on which we have all files stored. Now, i want to download all these files to a folder by looping through each directory and sub directory of the Azure Storage.

我是Azure存储的新宠。所以,请在帖子中考虑我的内容。我有一个Azure存储帐户,我们在其中存储了所有文件。现在,我想通过循环遍历Azure存储的每个目录和子目录将所有这些文件下载到文件夹。

Sample code:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "photo1.jpg".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("photo1.jpg");

// Save blob contents to a file.
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile"))
{
    blockBlob.DownloadToStream(fileStream);
} 

But i am not able to get all the 'Container' and its contents with subcontents.

但我无法通过子内容获得所有“容器”及其内容。

Help Appreciated!

1 个解决方案

#1


Use blobClient.ListContainers() to get all containers, and use container.ListBlobs() to get all blobs in a container.

使用blobClient.ListContainers()获取所有容器,并使用container.ListBlobs()获取容器中的所有blob。

#1


Use blobClient.ListContainers() to get all containers, and use container.ListBlobs() to get all blobs in a container.

使用blobClient.ListContainers()获取所有容器,并使用container.ListBlobs()获取容器中的所有blob。