title: How to download files from Azure Blob Storage with a Download Link
body: <p>I made an Azure Cloud Service, where you can upload and delete files to the cloud storage using Blobs. I wrote sucessfully a method where you can delete the uploaded blobs from the cloud service:</p>
  
  <pre><code> public string DeleteImage(string Name)
      {
          Uri uri = new Uri(Name);
          string filename = System.IO.Path.GetFileName(uri.LocalPath);
  
          CloudBlobContainer blobContainer = _blobStorageService.GetCloudBlobContainer();
          CloudBlockBlob blob = blobContainer.GetBlockBlobReference(filename);
  
          blob.Delete();
  
          return "File Deleted";
      }
  }
  </code></pre>
  
  <p>Here is also the code for View with HTML:</p>
  
  <pre><code>@{
  ViewBag.Title = "Upload";
  }
  
  &lt;h2&gt;Upload Image&lt;/h2&gt;
  
  &lt;p&gt;
  @using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = 
  "multipart/form-data" }))
  {
      &lt;input type="file" name="image"/&gt;
      &lt;input type="submit" value="upload" /&gt;
  }
  
  &lt;/p&gt;
  
  &lt;ul style="list-style-position:Outside;padding:0;"&gt;
  @foreach (var item in Model)
  {
  &lt;li&gt;
      &lt;img src="@item" alt="image here" width="100" height="100" /&gt;
      &lt;a id="@item" href="#" onclick="deleteImage ('@item');"&gt;Delete&lt;/a&gt;
  
  &lt;/li&gt;
  }
  &lt;/ul&gt;
  
  &lt;script&gt;
  function deleteImage(item) {
      var url = "/Home/DeleteImage";
      $.post(url, { Name: item }, function (data){
          window.location.href = "/Home/Upload";
      });
  }
  
  &lt;/script&gt; 
  </code></pre>
  
  <p>Now I want to write a similiar method so you can download each blob from the View. I tried to write the methode using exactly the same code from the delete but instead of </p>
  
  <pre><code>blob.delete();
  </code></pre>
  
  <p>now</p>
  
  <pre><code>blob.DownloadToFile(File);
  </code></pre>
  
  <p>This didn't work though. Is there a possibility to change the delete method so it downloads the chosen blob instead of deleting it?</p>
  
  <hr>
  
  <h2>Added Info</h2>
  
  <p>Here is the code of DownloadToFile method:</p>
  
  <pre><code>[HttpPost]
      public string DownloadImage(string Name)
      {
          Uri uri = new Uri(Name);
          string filename = System.IO.Path.GetFileName(uri.LocalPath);
  
          CloudBlobContainer blobContainer = 
  _blobStorageService.GetCloudBlobContainer();
          CloudBlockBlob blob = blobContainer.GetBlockBlobReference(filename);
  
          blob.DownloadToFile(filename, System.IO.FileMode.Create);
  
  
          return "File Downloaded";
      }
  </code></pre>
  
  <p>The name is just the whole filename that is uploaded. Filename is the data path.</p>
  
  <p>The Exception I get is: </p>
  
  <p>UnauthorizedAccessException: The access to the path "C:\Program Files\IIS Express\Eva Passwort.docx" is denied.]</p>
  
  <p>I think that the problem is that my application doesn't have a path to save the file. Is there a possibility to get a dialog where I can chose the path to save?</p>