title: Error downloading an object from Amazon S3 bucket using C#
body: <p>I have used the very basic code for downloading a file from Amazon S3.
  I have tried with two different codes.</p>
  
  <ol>
  <li><p>The one which is commented <code>GetObjectResponse</code> throwing error </p>
  
  <pre><code>System.Xml.XmlException: There are multiple root elements. Line 2, position 2.
  at System.Xml.XmlTextReaderImpl.Throw(Exception e)
  at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
  at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res)
  at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
  at System.Xml.XmlTextReaderImpl.Read()
  at System.Xml.XmlTextReader.Read()
  </code></pre>
  
  <p>and etc.,</p></li>
  <li><p>The code with the <code>TransferUtilityDownloadRequest</code>. Am not sure whether this method is correct or not. Found similar kind of example in <a href="http://docs.aws.amazon.com/AWSSdkDocsNET/latest/DeveloperGuide/net-dg-migration-guide-v2.html" rel="nofollow">Amazon Site</a> so tried. </p></li>
  </ol>
  
  <p><strong>Source Code</strong></p>
  
  <pre><code>  private static void AmazonS3Access()
      {
          string accessKey = "my_access_key";
          string secretKey = "my_secret_key";
  
          AmazonS3Config config = new AmazonS3Config();
          config.ServiceURL = "s3.amazonaws.com";
  
          AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                  accessKey,
                  secretKey,
                  config);
          GetObjectRequest request = new GetObjectRequest();
          request.BucketName = "bucket";
          request.Key = "myfile.extension";
          try
          {
              TransferUtilityDownloadRequest myfile = new TransferUtilityDownloadRequest();                
              myfile.WithBucketName(request.BucketName);
              myfile.WithKey(request.Key);
              myfile.WithFilePath("D:\\S3File\\myfile.extension");  
              //GetObjectResponse response = client.GetObject(request);
              //response.WriteResponseStreamToFile("D:\\S3File\\myfile.extension");
          }
          catch (Exception Ex)
          {
              Console.WriteLine(Ex.ToString());
          }
      }
  </code></pre>
  
  <p>How to download the object from Amazon S3. Thanks in advance.</p>
  
  <p>Note:</p>
  
  <ol>
  <li>Am using VS 2010 with .NetFramework 3.5</li>
  <li>Am using AmazonSDK.dll old version</li>
  </ol>
  
  <p><strong>Solution:</strong></p>
  
  <p>After adding the Network Proxy Credentials in the Program, it starts working fine.</p>