AWS SDK for .NET Documentation
DeleteObjects Method (request)
AmazonAmazon.S3AmazonS3DeleteObjects(DeleteObjectsRequest) Did this page help you?   Yes   No    Tell us about it...
Removes the specified objects from Amazon S3.
Declaration Syntax
C#
Parameters
request (DeleteObjectsRequest)
The DeleteObjectsRequest that defines the parameters of the operation.
Return Value
Returns a DeleteObjectsResponse from S3.
Remarks

The DeleteObjects operation removes the specified object from Amazon S3. Once deleted, there is no method to restore or undelete the objects.

DeleteObjectsException will be thrown if any of the deletes fail.

Examples

This example shows how to delete multiple objects in a single request.
Note that the call may not delete all objects. In that case, an exception will be thrown. This exception will contain the list of encountered delete errors.

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

// Create a DeleteObject request
DeleteObjectsRequest request = new DeleteObjectsRequest
{
    BucketName = "SampleBucket",
    Keys = new List<KeyVersion>
    {
        new KeyVersion("Item1"),
        // Versioned item
        new KeyVersion("Item2", "Rej8CiBxcZKVK81cLr39j27Y5FVXghDK"),
        // Item in subdirectory
        new KeyVersion("Logs/error.txt")
    }
};

try
{
    // Issue request
    DeleteObjectsResponse response = client.DeleteObjects(request);
}
catch (DeleteObjectsException doe)
{
    // Catch error and list error details
    DeleteObjectsErrorResponse errorResponse = doe.ErrorResponse;

    foreach (DeletedObject deletedObject in errorResponse.DeletedObjects)
    {
        Console.WriteLine("Deleted item " + deletedObject.Key);
    }
    foreach (DeleteError deleteError in errorResponse.DeleteErrors)
    {
        Console.WriteLine("Error deleting item " + deleteError.Key);
        Console.WriteLine(" Code - " + deleteError.Code);
        Console.WriteLine(" Message - " + deleteError.Message);
    }
}
Exceptions
ExceptionCondition
ArgumentNullException
WebException
AmazonS3Exception
DeleteObjectsException If any objects are not deleted during the operation.

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