Get Files and Folders From Amazon S3 Cloud in Asp.net C#

How to get or list all files and folders from Amazon S3 Cloud in asp.net c#?


Steps


  1. Install NuGet "AWSSDK" from Nuget Manage.
  2. Put below code in c#
            AWSCredentials credentials = new BasicAWSCredentials("Access Key", "Secret Key");
            AmazonS3Config config = new AmazonS3Config();
            config.ServiceURL = "s3.amazonaws.com";
            config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("ap-south-1");
            AmazonS3Client client;
            string[] folderArry = { "ABC" };
            using (client = new AmazonS3Client(credentials, config))
            {
                ListObjectsRequest request = new ListObjectsRequest
                {
                    BucketName = "BucketName"
                };

                do
                {
                    ListObjectsResponse response = client.ListObjects(request);
                    IEnumerable<S3Object> folders = response.S3Objects.Where(x => x.Key.Contains("ABC/")).ToList();
                    if (folders.Count() > 0)
                    {

                    }

                    if (response.IsTruncated)
                    {
                        request.Marker = response.NextMarker;
                    }
                    else
                    {
                        request = null;
                    }
                } while (request != null);
            }

Comments

Popular posts from this blog

Convert Html Code to Image JPG PNG in asp.net C#