• Windows Mac Android Linux
    Tools News Blog How To
  • Articles (current)
  • Submit Software
    • Register Login

    Create Amazon S3 Bucket if does not exist C#

    • Qayyum
    • July 13, 2018
    • 15,585

    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


    UberEats Clone is the Perfect Way to Start Your Online Food Delivery Business

    UberEats Clone is the Perfect Way to Start Your On...

    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

    Most Read
    • Big list of sample videos for testers
    • 17 Best Free Word to PDF Converter Software for Windows
    • How to remove Omiga Plus?
    • 61 Most Used VLC Keyboard Shortcuts (Hotkeys)
    • Big list of sample audio files for testers
    Popular Downloads
    • Adobe Flash PlayerAdobe Flash Player
    • CyberLink YouCamCyberLink YouCam
    • GoAnimateGoAnimate
    • 7-PDF Maker7-PDF Maker
    • SketchBook Pro (32-Bit) SketchBook Pro (32-Bit)
    • PDF24 CreatorPDF24 Creator
    • Foxit ReaderFoxit Reader
    • Excel 2016 Password Remover FreeExcel 2016 Password Remover Free
    • Ghost Mouse Auto ClickerGhost Mouse Auto Clicker
    • Free Word to PDF ConverterFree Word to PDF Converter
    • Adobe Acrobat ReaderAdobe Acrobat Reader
    • WinRARWinRAR
    • FL Studio 12FL Studio 12
    • Free PDF ReaderFree PDF Reader
    • Google Web DesignerGoogle Web Designer

    Standalone Installer

    Standalone Installer © 2022

    Our Projects
    • Free PDF Solutions
    • Media Freeware
    • Free Picture Solutions
    • Tiny Mini Tools
    • PDF Tools
    Standalone
    • Online Tools
    • News
    • Blog
    • How to
    Legal
    • Privacy Policy
    • Contact
    • Report
    Download this file
    OSZAR »