title: How to delete a file from azure blob storage after downloading it
body: <p>I'm working on a blob storage system where my files are stored.
  Right now, I'm able to delete/undelete files from my blob container.
  I'm trying to download a file back from my controller to browser and delete the file.</p>
  
  <p>Here's my download controller</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public ActionResult DownloadBlob(string name) {
              CloudBlobContainer container = GetCloudBlobContainer();
              var resultSegment = container.ListBlobsSegmentedAsync(name.Split('/')[0],true ,BlobListingDetails.All,null,null,null,null).Result;
              CloudBlockBlob target = (CloudBlockBlob)resultSegment.Results.FirstOrDefault(e =&gt; e.Uri.Segments.Last() == name.Split('/')[1]);
              //var directory = container.GetDirectoryReference(name.Split('/')[0]);
              //var block = directory.GetBlockBlobReference(name.Split('/')[1]);
  
              if (target.ExistsAsync().Result) {
              } else {
                  target.UndeleteAsync().Wait();
              }
  
              Stream stream = target.OpenReadAsync().Result;
              string contentType = target.Properties.ContentType;
              ;
  
              target.DeleteIfExistsAsync();
  
              return new FileStreamResult(stream, contentType) {
                  FileDownloadName = "Downloaded_" + name.Split('/')[1]
              };
      }
  </code></pre>
  
  <p>So if I have a deleted file, I want to undelete it, download it then delete it again.(Soft Delete is turned on)
  Is there a way to do this so deletion executes after return statement</p>