Saturday, January 03, 2009

AWS - S3 - ThreeSharp - Deleting a bucket (must delete it's contents first)

If anyone's interested, then this is the rather crude code I hacked together to delete entire buckets (including their contents) within the ThreeSharp Forms sample for AWS S3
 

        private void button1_Click(object sender, EventArgs e)

        {

            while (listBoxObjects.Items.Count > 0)

            {

                this.listBoxObjects.SelectedIndex = 0;

                using (ObjectDeleteRequest request = new ObjectDeleteRequest(this.comboBoxBucketNames.SelectedItem.ToString(), this.listBoxObjects.SelectedItem.ToString()))

                {

                    //request.RedirectUrl = redirectUrl;

                    using (ObjectDeleteResponse response = service.ObjectDelete(request))

                    { }

                }

                this.listBoxObjects.Items.Remove(this.listBoxObjects.SelectedItem);

            }

 

            using (BucketDeleteRequest r = new BucketDeleteRequest(this.comboBoxBucketNames.Text))

            {

                using (BucketDeleteResponse resp = service.BucketDelete(r))

                {

                    Debug.WriteLine(resp.StatusCode);

                }

            }

        }

No comments:

Post a Comment