title: Download file in azure storage using ASP.Net core2
body: <p>I have web application and user should be able to download files which are stored in the azure storage.</p>
  
  <pre><code>public class FileDownloader
  {
      private string constring = "myconnectionstring";
  
      public async Task download(string fileName, string directoryName)
      {
          try
          {
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(constring);
              CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
              CloudFileShare share = fileClient.GetShareReference("myreference");
              string userName = Environment.UserName;
  
  
              if (await share.ExistsAsync())
              {
                  // Get a reference to the root directory for the share.
                  CloudFileDirectory rootDir = share.GetRootDirectoryReference();
  
                  // Get a reference to the directory we created previously.
                  CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(directoryName);
  
                  // Ensure that the directory exists.
                  if (await sampleDir.ExistsAsync())
                  {
                      // Get a reference to the file we created previously.
                      CloudFile file = sampleDir.GetFileReference(fileName);
  
                      // Ensure that the file exists.
                      if (await file.ExistsAsync())
                      {
  
                          await file.DownloadToFileAsync(string.Format("C:/Users/" + userName + "/Downloads/{0}", fileName), FileMode.Create);
                      }
                  }
              }
  
          }
          catch (Exception ex)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>This is my code.</p>
  
  <p>It works perfectly when I run application in my local environment(localhost) but when I deploy it and host it in the azure, it isn't downloading the files.</p>