Articles → AWS SDK AND CSHARP → Upload File(S) And Folder(S) On S3 Bucket Using C# Code

Upload File(S) And Folder(S) On S3 Bucket Using C# Code


  1. Create s3 bucket.
  2. Create a console application and write code.
  3. Output.

Create S3 Bucket

Picture showing the S3 bucket created in AWS console
Click to Enlarge

Create A Console Application And Write Code

using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Transfer;
using System.IO;

namespace dotnetS3
    class Program

        public static void Main(string[] args)

            string bucketName = "gyansangrah-bucket";


        static void UploadFilesAndFolder(string bucketName)
            var region = RegionEndpoint.GetBySystemName("us-east-2");
            AWSCredentials credentails = new BasicAWSCredentials("<Access Id>", "<Secret Key>");

            AmazonS3Client client = new AmazonS3Client(credentails);

            TransferUtility utility = new TransferUtility(client);
            TransferUtilityUploadDirectoryRequest transferUtilityUploadDirectoryRequest
                = new TransferUtilityUploadDirectoryRequest()
                    BucketName = bucketName,
                    Directory = @"C:\temp\cluster",
                    SearchOption = SearchOption.AllDirectories




Picture showing the list of files and folders to be uploaded on S3 bucket
Click to Enlarge


Picture showing the files and folders uploaded on the S3 bucket
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Thursday, February 10, 2022


Your Email Id  
Query/FeedbackCharacters remaining 250