title: azure storage / c#: Download all files from a directory in a container
body: <p>Is there an easy way to download all files and maintain the directory structure from inside of a container?</p>
  
  <p>For example, I've uploaded the following directory to my Azure Storage account in container "users".</p>
  
  <p>../username/files/
  ../username/files/default.htm
  ../username/files/1.txt
  ../username/files/2.txt</p>
  
  <p>The code below will download the default.htm file to C:\users\username\files\default.htm</p>
  
  <p>The problem is I don't want to download a specific file. I want to be able to get every file inside of users/username/ and have it output the same directory structure at a desired local storage path.</p>
  
  <p>I will have multiple "directories" inside of this container (different users) and their structure won't always be the same, some may have multiple sub-directories with files, some may have none, etc. So I'm really looking for a way to say :</p>
  
  <p>Download ALL FROM "users/username" TO C:\users\username\</p>
  
  <pre><code>private static void DownloadFromAzureStorage()// RUN on new server
  {
      string azureStorageAccountName = 
      ConfigurationManager.AppSettings["AzureStorageAccountName"];
      string azureStorageAccountKey = 
      ConfigurationManager.AppSettings["AzureStorageAccountKey"];
      string target = 
      ConfigurationManager.AppSettings["TargetDirectoryPath"];
      //C:\username\files\
      var storageCredentials = new 
      StorageCredentials(azureStorageAccountName, azureStorageAccountKey);
      var csa = new CloudStorageAccount(storageCredentials, true);
  
      CloudBlobClient blobClient = csa.CreateCloudBlobClient();
      CloudBlobContainer container = 
      blobClient.GetContainerReference("users");
  
      CloudBlockBlob blockBlob = 
      container.GetBlockBlobReference("username/files/default.htm");
      string path = (target + "default.htm");
      blockBlob.DownloadToFile(path, FileMode.OpenOrCreate);
  }
  </code></pre>