• Home (current)
  • Online Tools
  • Categories
  • News
  • Blog
  • How To
  • Submit Your Software
  • Blog News How To Submit Software Contact
    • Register Login

    Create Amazon S3 Bucket if does not exist C#

    • Qayyum
    • July 13, 2018
    • 3,253

    To create Amazon S3 bucket i used nugget package which you can install by running following nugget command in Visual Studio.

    Install-Package AWSSDK.S3 -Version 3.3.19

    The code part:

    public class s3
    {
    AmazonS3Client client;
    <em>
    string accessKey = Properties.Settings.Default.s3AccessKey;
    string secretKey = Properties.Settings.Default.s3SecretKey;
    string bucket = Properties.Settings.Default.s3Bucket;
    </em>

    public async Task<int> CreateBucket()
    {
    try
    {
    using (client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast1))
    {
    bool bucketExist = false;

    S3DirectoryInfo root = new S3DirectoryInfo(client, "");
    Console.WriteLine(accessKey);
    Console.WriteLine(secretKey);
    Console.WriteLine(bucket);

    foreach (S3DirectoryInfo subDirectory in root.GetDirectories())
    {
    if (subDirectory.Name == bucket)
    {
    Console.WriteLine(subDirectory.Name);
    bucketExist = true;
    return 1;
    }
    }

    if (!bucketExist)
    {
    root.CreateSubdirectory(bucket);
    return 2;
    }
    }

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    return 0;
    }
    }

    How to use:

    s3 s = new s3();
    int response = await s.CreateBucket();

    switch (response)
    {
    case 1:
    lblCreateBucketStatus.Text = "Bucket already exists, try new name.";
    lblCreateBucketStatus.ForeColor = Color.Orange;
    break;
    case 2:
    lblCreateBucketStatus.Text = "Bucket created.";
    lblCreateBucketStatus.ForeColor = Color.Green;
    break;
    case 0:
    lblCreateBucketStatus.Text = "Failed, Please try again (maybe different bucket name).\nBucket name should be lowercase, no spaces.";
    lblCreateBucketStatus.ForeColor = Color.Red;
    MessageBox.Show("");
    break;
    default:
    break;
    }

    You May Also Like View all


    How to download Classic Skype?

    How to download Classic Skype?

    VirusTotal Scanner PHP

    VirusTotal Scanner PHP

    Cyclance is a smart antivirus that uses artificial intelligence to keep your system fully protected

    Cyclance is a smart antivirus that uses artificial...

    Create Amazon S3 Bucket if does not exist C#

    Create Amazon S3 Bucket if does not exist C#

    Big list of various character length usernames

    Big list of various character length usernames

    Search Amazon by Image or text from right click menu

    Search Amazon by Image or text from right click me...

    Most Read
    • 17 Best Free Word to PDF Converter Software for Windows
    • Big list of sample videos for testers
    • How to remove Omiga Plus?
    • 5 Best Free Video Repair tools to Fix Any Video
    • Cyclance is a smart antivirus that uses artificial intelligence to keep your system fully protected
    Popular Downloads
    • Adobe Flash PlayerAdobe Flash Player
    • 7-PDF Maker7-PDF Maker
    • PDF24 CreatorPDF24 Creator
    • Free Word to PDF ConverterFree Word to PDF Converter
    • Free PDF ReaderFree PDF Reader
    • Ghost Mouse Auto ClickerGhost Mouse Auto Clicker
    • Excel 2016 Password Remover FreeExcel 2016 Password Remover Free
    • MP4 Video Repair ToolMP4 Video Repair Tool
    • HD Youtube Downloader FreeHD Youtube Downloader Free
    • WinRARWinRAR
    • VLC Media PlayerVLC Media Player
    • Word into PDF ConverterWord into PDF Converter
    • Solid PDF CreatorSolid PDF Creator
    • WinZipWinZip
    • Word Excel PowerPoint to Pdf ConverterWord Excel PowerPoint to Pdf Converter

    Submit Softwares - Contact - Privacy Policy - © StandaloneInstaller.com 2018

    Download this file