title: Upload files to azure file storage via Web API
body: <p>I'm trying to upload files to our cloud storage at Azure but only get a <code>bad request 400</code> response. Running the application on local host and trying to connect to our account at Azure.</p>
  
  <p>When I place this in a try/catch I get a <code>bad request 400</code> on the last line</p>
  
  <blockquote>
    <p>cloudFile.Create(fileSize);</p>
  </blockquote>
  
  <p>This line below returns null, yet the file share exists when I check it in the if statement:</p>
  
  <blockquote>
    <p>var listShares = fileClient.ListShares(); // null</p>
  </blockquote>
  
  <p>I've only found one example on how to actually upload a file like this:</p>
  
  <pre><code>// Connect to Azure Storage         
  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
          CloudConfigurationManager.GetSetting("AzureStorageConnectionString"));
  
      //Create a CloudFileClient object for credentialed access to File storage.
      CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
  
      //Get a reference to the file share we created previously.
      CloudFileShare share = fileClient.GetShareReference("appbackup");
  
      var listShares = fileClient.ListShares();
  
      //Ensure that the share exists.
      if (share.Exists())
      {
          //Get a reference to the root directory for the share.
          CloudFileDirectory rootDir = share.GetRootDirectoryReference();
  
          //Get a reference to the sampledir directory we created previously.
          CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("sampledir");
  
          //Ensure that the directory exists.
          if (sampleDir.Exists())
          {
              var test = rootDir.ListFilesAndDirectories();
              var Credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("accountName", "keyValue");
  
              string stringUri = storageAccount.FileStorageUri.PrimaryUri + share.Name + "/sampledir/";
  
              Uri theUri = new Uri(stringUri);
              CloudFile cloudFile = new CloudFile(theUri, Credentials);
              System.IO.FileInfo fi = new System.IO.FileInfo(filepath);
              long fileSize = fi.Length;
              cloudFile.Create(fileSize);
          }
      }
  </code></pre>