title: Downloading images from Azure Blob Storage
body: <p>I'm writing a program that can download images from specified file paths from our Azure Storage container.</p>
  
  <p>I have put together the following function from code found online and then removing the errors. However, the final errors I can't get rid of. </p>
  
  <p>Full code below: </p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using Microsoft.WindowsAzure.Storage;
  
  using Microsoft.WindowsAzure.Storage.Blob;
  using System.IO;
  namespace WarehousePhotoProgram
  {
      public partial class Form1 : Form
      {
          string storageConnectionString = Environment.GetEnvironmentVariable("storageconnectionstring");
  
      public Form1()
  
  
         {
              InitializeComponent();
          }
  
          private void DownloadFileFromBlob(string fileName, string containerName)
          {
              CloudStorageAccount account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(storageConnectionString));
              CloudBlobClient blobClient = account.CreateCloudBlobClient();
              CloudBlobContainer container = blobClient.GetContainerReference(containerName);
              CloudBlob blob = container.GetBlobReference(fileName);
              MemoryStream memStream = new MemoryStream();
              blob.DownloadToStream(memStream);
              Response.ContentType = blob.Properties.ContentType;
              Response.AddHeader("Content-Disposition", "Attachment; filename=" + fileName.ToString());
              Response.AddHeader("Content-Length", blob.Properties.Length.ToString());
              Response.BinaryWrite(memStream.ToArray());
  
          }
      }
     }
  </code></pre>
  
  <p>The code currently errors on <code>RoleEnvironment</code> saying the namespace doesn't exist, am I missing an assembly reference? Or do I need to import another <code>using</code>. The second error is on all of the <code>Result.</code> again stating <code>Response</code> doesn't exist. </p>
  
  <p>Is this also the best approach to take regarding downloading images from BlobStorage or should I take another approach at it?</p>
  
  <p>EDIT: I resolved the <code>RoleEnvironment</code> error with the help of the given answer. Now trying to determine what the Response section of the code needs changing too.</p>
  
  <pre><code>        public Form1()
      {
          InitializeComponent();
          //_storageAccount = CloudStorageAccount.Parse(storageConnectionString);
  
          DownloadFileFromBlob("029000/1.png", "warehouseimages", "Desktop");
      }
  
      private void DownloadFileFromBlob(string fileName, string containerName, string localFilePath)
      {
          CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
          CloudBlobClient blobClient = account.CreateCloudBlobClient();
          CloudBlobContainer container = blobClient.GetContainerReference(containerName);
          CloudBlob blob = container.GetBlobReference(fileName);
          using (var fileStream = System.IO.File.OpenWrite(localFilePath))
          {
              blob.DownloadToStream(fileStream);
              MessageBox.Show("SUCCESS");
          }
      }
  </code></pre>