AWS SDK for .NET Documentation
DeleteBucket Method (request)
AmazonAmazon.S3AmazonS3DeleteBucket(DeleteBucketRequest) Did this page help you?   Yes   No    Tell us about it...
Deletes an S3 bucket.
Declaration Syntax
C#
Parameters
request (DeleteBucketRequest)
The DeleteBucketRequest that defines the parameters of the operation.
Return Value
Returns a DeleteBucketResponse from S3.
Remarks
All objects in the bucket must be deleted before the bucket itself can be deleted. Only the owner of a bucket can delete it, regardless of the bucket's access control policy.
Examples

This example shows how to delete an bucket.

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

// Construct request
DeleteBucketRequest request = new DeleteBucketRequest
{
    BucketName = "SampleBucket"
};

// Issue call
DeleteBucketResponse response = client.DeleteBucket(request);

This example shows how to delete all items in a bucket, and then delete the actual bucket.

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

// List and delete all objects
ListObjectsRequest listRequest = new ListObjectsRequest
{
    BucketName = "SampleBucket"
};

ListObjectsResponse listResponse;
do
{
    // Get a list of objects
    listResponse = client.ListObjects(listRequest);
    foreach (S3Object obj in listResponse.S3Objects)
    {
        // Delete each object
        client.DeleteObject(new DeleteObjectRequest
        {
            BucketName = obj.BucketName,
            Key = obj.Key
        });
    }

    // Set the marker property
    listRequest.Marker = listResponse.NextMarker;
} while (listResponse.IsTruncated);

// Construct DeleteBucket request
DeleteBucketRequest request = new DeleteBucketRequest
{
    BucketName = "SampleBucket"
};

// Issue call
DeleteBucketResponse response = client.DeleteBucket(request);
Exceptions

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