AWS SDK for .NET Documentation
GetObject Method (request)
AmazonAmazon.S3AmazonS3ClientGetObject(GetObjectRequest) Did this page help you?   Yes   No    Tell us about it...
Fetches the most recent version of an S3 object.
Declaration Syntax
C#
public GetObjectResponse GetObject(
	GetObjectRequest request
)
Parameters
request (GetObjectRequest)
The GetObjectRequest that defines the parameters of the operation.
Return Value
Returns a GetObjectResponse from S3.
Remarks

You must have READ access to the object.

If READ access is granted to an anonymous user, an object can be retrieved without an authorization header. Providing a version-id for the object will fetch the specific version from S3 instead of the most recent one.

You should wrap the response you get from calling GetObject in a using clause. This ensures that all underlying IO resources allocated for the response are disposed once the response has been processed. This is one way to call GetObject:

CopyC#
using (GetObjectResponse response = s3Client.GetObject(request))
{
    ... Process the response:
    Get the Stream, get the content-length, write contents to disk, etc
}
To see what resources are cleaned up at the end of the using block, please see Dispose()()()()

Examples

This example shows how to get an object.

CopyGetObject sample
// Create a client
AmazonS3Client client = new AmazonS3Client();

// Create a GetObject request
GetObjectRequest request = new GetObjectRequest
{
    BucketName = "SampleBucket",
    Key = "Item1"
};

// Issue request and remember to dispose of the response
using (GetObjectResponse response = client.GetObject(request))
{
    using (StreamReader reader = new StreamReader(response.ResponseStream))
    {
        string contents = reader.ReadToEnd();
        Console.WriteLine("Object - " + response.Key);
        Console.WriteLine(" Version Id - " + response.VersionId);
        Console.WriteLine(" Contents - " + contents);
    }
}
Exceptions

Assembly: AWSSDK (Module: AWSSDK) Version: 1.5.60.0 (1.5.60.0)