try
{
AmazonS3Config config = new AmazonS3Config();
config.RegionEndpoint ="Your region"
m_s3Client = new AmazonS3Client("Your access key",
"Your secret key",
config);
m_connected = true;
}
catch (Exception ex)
{
m_connected = false;
}
if (m_connected)
try
{
GetObjectRequest request=
new GetObjectRequest
{
BucketName = bucketName,
Key = Key
};
using (GetObjectResponse response = m_s3Client.GetObject(request))
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
string contentType = response.Headers["Content-Type"];
string responseBody = reader.ReadToEnd();
if (File.Exists(SelectedToDownload.FileName))
File.Delete(SelectedToDownload.FileName);
File.WriteAllText(SelectedToDownload.FileName, responseBody);
string readText = File.ReadAllText(SelectedToDownload.FileName);
}
catch (AmazonS3Exception e)
{
}