Example #1
0
        private void buttonBuckets_CreateBucket_Click(object sender, EventArgs e)
        {
            string strBucketName = textBoxBuckets_BucketName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Bucket Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cS3BucketOperations = new c_S3BucketOperations(strBucketName);
            string strResult = String.Empty;

            try
            {
                if (cS3BucketOperations.bDoesBucketExist() == true)
                {
                    MessageBox.Show("Bucket  " + strBucketName + " already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (DialogResult.Yes != (MessageBox.Show("Are you sure you want to make Bucket " + strBucketName + "?", "Continue?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)))
                {
                    return;
                }

                cS3BucketOperations.CreateBucket(out strResult);
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText("\r\n" + Exb1.Message);
            }
            textBoxMessages.AppendText("\r\n" + strResult);
        }
Example #2
0
        // How to filter using Delimiter and Prefix
        // https://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html
        //https://edunyte.com/2015/03/aws-s3-get-list-of-all-s3-objects-in-bucket/
        private void buttonBuckets_ListObjects_Click(object sender, EventArgs e)
        {
            string strError      = String.Empty;
            string strBucketName = textBoxBuckets_BucketName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Bucket Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <string> lststr_Buckets = new List <string>();

            cS3BucketOperations = new c_S3BucketOperations();
            cS3BucketOperations.strBucketName = strBucketName;

            DataSet ds = new DataSet();

            try
            {
                cS3BucketOperations.ListingObjects(ds, out strError);
                dataGridViewBuckets_Objects.DataSource = ds.Tables[0];
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText(Exb1.Message);
            }
        }
Example #3
0
        private void buttonBuckets_BucketExists_Click(object sender, EventArgs e)
        {
            bool   bExists       = false;
            string strBucketName = textBoxBuckets_BucketName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Bucket Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cS3BucketOperations = new c_S3BucketOperations(strBucketName);
            try
            {
                bExists = cS3BucketOperations.bDoesBucketExist();
            }
            catch (Exception ex1)
            {
                textBoxMessages.Text = textBoxMessages.Text + Environment.NewLine + ex1.Message;
            }
            if (bExists == true)
            {
                textBoxMessages.Text = textBoxMessages.Text + Environment.NewLine + "Bucket " + cS3BucketOperations.strBucketName + " Exists...";
            }
            else
            {
                textBoxMessages.Text = textBoxMessages.Text + Environment.NewLine + "Bucket " + cS3BucketOperations.strBucketName + " does not Exist...";
            }
        }
Example #4
0
        private void buttonBuckets_ListBuckets_Click(object sender, EventArgs e)
        {
            string        strError       = String.Empty;
            List <string> lststr_Buckets = new List <string>();

            cS3BucketOperations = new c_S3BucketOperations();
            try
            {
                cS3BucketOperations.getBuckets_AsStrings(lststr_Buckets, out strError);
                textBoxMessages.Lines = lststr_Buckets.ToArray();
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText(Exb1.Message);
            }
            DataSet ds = new DataSet();

            try {
                cS3BucketOperations.getBuckets_AsTable(ds);
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText(Exb1.Message);
            }

            if (ds.Tables[0].Rows.Count > 0)
            {
                dataGridViewBuckets1.DataSource = ds.Tables[0];
            }
            else
            {
                textBoxMessages.AppendText("No Buckets Found.");
            }
        }
Example #5
0
        private void buttonBuckets_UploadFiles_Click(object sender, EventArgs e)
        {
            string strBucketName = textBoxBuckets_BucketName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Bucket Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\Temp\AWS_Test_Files\",
                Title            = "Select Files To Upload",
                CheckFileExists  = true,
                CheckPathExists  = true,
                Multiselect      = true,
                //DefaultExt = "txt",
                //Filter = "txt files (*.txt)|*.txt",
                //FilterIndex = 2,
                RestoreDirectory = true // , // restores the current directory before closing.
                                        //ReadOnlyChecked = true,
                                        //ShowReadOnly = true
            };

            string        strFiles    = String.Empty;
            List <string> lststrFiles = new List <string>();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //textBoxMessages.AppendText(openFileDialog1.FileName);
                foreach (String file in openFileDialog1.FileNames)
                {
                    textBoxMessages.AppendText("\r\n" + file);
                    strFiles += "\r\n" + file;
                    lststrFiles.Add(file);
                }
            }
            if (DialogResult.Yes != (MessageBox.Show("Are you sure you want to upload these files to the " + strBucketName + " Bucket?" + strFiles, "Continue?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)))
            {
                return;
            }

            string        strResult = String.Empty;
            StringBuilder sb        = new StringBuilder();

            cS3BucketOperations = new c_S3BucketOperations(strBucketName);

            foreach (string strFileName in lststrFiles)
            {
                cS3BucketOperations.UploadFile(strFileName, out strResult);
                sb.Append("\r\n" + strResult);
            }
            textBoxMessages.AppendText(sb.ToString());
        }
Example #6
0
        private void buttonBuckets_CreateFolder_Click(object sender, EventArgs e)
        {
            string strBucketName = textBoxBuckets_FolderName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Folder Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cS3BucketOperations = new c_S3BucketOperations(strBucketName);
            string strResult = String.Empty;
        }
Example #7
0
        private void buttonBuckets_PreSignedURL_Click(object sender, EventArgs e)
        {
            string strResult = String.Empty;
            string strError  = String.Empty;

            cS3BucketOperations = new c_S3BucketOperations();
            try
            {
                cS3BucketOperations.strBucketName = textBoxBuckets_BucketName.Text.Trim();
                cS3BucketOperations.strObjectName = textBoxBuckets_ObjectName.Text.Trim();
                cS3BucketOperations.GeneratePreSignedUrl(out strResult, out strError);
                textBoxMessages.AppendText("\r\nPeSignedURL = " + strResult);
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText(Exb1.Message);
            }
        }
Example #8
0
        private void buttonBuckets_DeleteBucket_Click(object sender, EventArgs e)
        {
            string strBucketName = textBoxBuckets_BucketName.Text.Trim();

            if (strBucketName == String.Empty)
            {
                MessageBox.Show("There needs to be Bucket Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cS3BucketOperations = new c_S3BucketOperations(strBucketName);
            string strError = String.Empty;

            try
            {
                if (cS3BucketOperations.bDoesBucketExist() == false)
                {
                    MessageBox.Show("Bucket  " + strBucketName + " was not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (DialogResult.Yes != (MessageBox.Show("Are you sure you want to delete the Bucket " + strBucketName + "?", "Continue?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)))
                {
                    return;
                }

                cS3BucketOperations.DeleteObjectNonVersionedBucket(out strError);
            }
            catch (Exception Exb1)
            {
                textBoxMessages.AppendText("\r\n" + Exb1.Message);
            }
            if (strError != "")
            {
                textBoxMessages.AppendText(strError);
            }
            else
            {
                textBoxMessages.AppendText("\r\nBucket:" + strBucketName + " Deleted.");
            }
        }