Using C# and amazon .Net SDK, able to list all the files with in a amazon S3 folder as below:
ListObjectsRequest request = new ListObjectsRequest();
request.BucketName = _bucketName; //Amazon Bucket Name
request.Prefix = _sourceKey; //Amazon S3 Folder path
do
{
ListObjectsResponse response = _client.ListObjects(request);//_client - AmazonS3Client
Output
Folder
Folder/file1.pdf
Folder/file2.pdf
Folder/file3.pdf
But i wanted to achieve something like this:
Desired Output
file1.pdf
file2.pdf
file3.pdf
Thanks in advance
Also you can use the following c# code to retrieve the files information.
var bucketName = "your bucket";
var s3Client = new AmazonS3Client("your access key", "your secret key");
var dir = new S3DirectoryInfo(s3Client, bucketName, "your AmazonS3 folder name");
foreach (IS3FileSystemInfo file in dir.GetFileSystemInfos())
{
Console.WriteLine(file.Name);
Console.WriteLine(file.Extension);
Console.WriteLine(file.LastWriteTime);
}
I am using amazon AWSSDK.Core and AWSSDK.S3 version 3.1.0.0 for .net 3.5. I hope it can help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With