简体   繁体   中英

How to download all files from Azure Storage using C#?

I am new bee to Azure Storage . So, please consider my content in post. I have a Azure Storag e 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 .

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM