当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3Client.DeleteBucket方法代码示例

本文整理汇总了C#中Amazon.S3.AmazonS3Client.DeleteBucket方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.DeleteBucket方法的具体用法?C# AmazonS3Client.DeleteBucket怎么用?C# AmazonS3Client.DeleteBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.S3.AmazonS3Client的用法示例。


在下文中一共展示了AmazonS3Client.DeleteBucket方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteBucket

 public static void DeleteBucket(string bucketName)
 {
     using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
     {
         client.DeleteBucket(bucketName);
     }
 }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:7,代码来源:Repository.cs

示例2: DeleteBucket

        public virtual void DeleteBucket(AmazonS3Client s3Client, string bucketName)
        {
            // First, try to delete the bucket.
            var deleteBucketRequest = new DeleteBucketRequest
            {
                BucketName = bucketName
            };

            try
            {
                s3Client.DeleteBucket(deleteBucketRequest);
                // If we get here, no error was generated so we'll assume the bucket was deleted and return.
                return;
            }
            catch (AmazonS3Exception ex)
            {
                if (!ex.ErrorCode.Equals("BucketNotEmpty"))
                {
                    // We got an unanticipated error. Just rethrow.
                    throw;
                }
            }

            // If we got here, then our bucket isn't empty so we need to delete the items in it first.

            DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest {BucketName = bucketName};

            foreach (S3Object obj in s3Client.ListObjects(new ListObjectsRequest {BucketName = bucketName}).S3Objects)
            {
                // Add keys for the objects to the delete request
                deleteObjectsRequest.AddKey(obj.Key, null);
            }

            // Submit the request
            s3Client.DeleteObjects(deleteObjectsRequest);

            // The bucket is empty now, so delete the bucket.
            s3Client.DeleteBucket(deleteBucketRequest);
        }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:39,代码来源:SolutionCode.cs

示例3: DeleteAllBuckets

        public static void DeleteAllBuckets()
        {
            using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
            {
                var response = client.ListBuckets();

                foreach (var bucket in response.Buckets)
                {
                    DeleteAllBucketItems(bucket.BucketName);

                    client.DeleteBucket(bucket.BucketName);
                }
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:14,代码来源:Repository.cs

示例4: RemoveLabBuckets

        public virtual void RemoveLabBuckets(AmazonS3Client s3Client, List<string> bucketNames)
        {
            foreach (var bucketName in bucketNames)
            {
                try
                {
                    ListObjectsResponse listObjectsResponse =
                        s3Client.ListObjects(new ListObjectsRequest {BucketName = bucketName});
                    foreach (var s3Object in listObjectsResponse.S3Objects)
                    {
                        var deleteObjectRequest = new DeleteObjectRequest
                        {
                            BucketName = bucketName,
                            Key = s3Object.Key
                        };
                        s3Client.DeleteObject(deleteObjectRequest);
                    }

                    s3Client.DeleteBucket(new DeleteBucketRequest {BucketName = bucketName});
                }
                catch (AmazonS3Exception s3E)
                {
                    if (!s3E.ErrorCode.Equals("NoSuchBucket"))
                    {
                        // This error wasn't expected, so rethrow.
                        throw;
                    }
                }
            }
        }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:30,代码来源:SolutionCode.cs

示例5: DeleteDirectory

 /// <summary>
 /// delete bucket from s3
 /// </summary>
 /// <param name="PathName"></param>
 /// <returns></returns>
 public bool DeleteDirectory(string PathName)
 {
     try
     {
         //amazon client
         using (var client = new AmazonS3Client())
         {
             //delete bucket request
             using (var response = client.DeleteBucket(new DeleteBucketRequest()
                 .WithBucketName(PathName)))
             {
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.ToString());
     }
     return false;
 }
开发者ID:yonglehou,项目名称:Bermuda,代码行数:26,代码来源:StorageAmazon.cs

示例6: BucketSamples

        public void BucketSamples()
        {
            {
                #region ListBuckets Sample

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

                // Issue call
                ListBucketsResponse response = client.ListBuckets();

                // View response data
                Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName);
                foreach (S3Bucket bucket in response.Buckets)
                {
                    Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate);
                }

                #endregion
            }

            {
                #region BucketPolicy Sample

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

                // Put sample bucket policy (overwrite an existing policy)
                string newPolicy = @"{ 
    ""Statement"":[{ 
    ""Sid"":""BasicPerms"", 
    ""Effect"":""Allow"", 
    ""Principal"": ""*"", 
    ""Action"":[""s3:PutObject"",""s3:GetObject""], 
    ""Resource"":[""arn:aws:s3:::samplebucketname/*""] 
}]}";
                PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest
                {
                    BucketName = "SampleBucket",
                    Policy = newPolicy
                };
                client.PutBucketPolicy(putRequest);


                // Retrieve current policy
                GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                string policy = client.GetBucketPolicy(getRequest).Policy;

                Console.WriteLine(policy);
                Debug.Assert(policy.Contains("BasicPerms"));


                // Delete current policy
                DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteBucketPolicy(deleteRequest);


                // Retrieve current policy and verify that it is null
                policy = client.GetBucketPolicy(getRequest).Policy;
                Debug.Assert(policy == null);

                #endregion
            }

            {
                #region GetBucketLocation Sample

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

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

                // Issue call
                GetBucketLocationResponse response = client.GetBucketLocation(request);

                // View response data
                Console.WriteLine("Bucket location - {0}", response.Location);

                #endregion
            }

            {
                #region PutBucket Sample

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

                // Construct request
                PutBucketRequest request = new PutBucketRequest
                {
//.........这里部分代码省略.........
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:101,代码来源:BaseS3Samples.cs


注:本文中的Amazon.S3.AmazonS3Client.DeleteBucket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。