Search code examples
amazon-s3subdirectory

Set a link in Asp.net to S3 folder


I have an S3 bucket and Folders (image and icon folders). I need to set an anchor (or equivalent) to the files in those folders. I want just the link to show up on the page and when the user clicks on it, it will download to their local.

I have searched for a solution but was unable to find any.

Thanks in advance. Mark


Solution

  • Finally found this:

    AmazonS3Client s3Client = new AmazonS3Client("Key", "secret key", RegionEndpoint.USEast1);
                S3DirectoryInfo dir = new S3DirectoryInfo(s3Client, "bucket name", "FOLDER NAME");
                foreach (IS3FileSystemInfo file in dir.GetFileSystemInfos())
                {
                    UWDocs.HRef = file.FullName;
                    //Console.WriteLine(file.Name);
                    //Console.WriteLine(file.Extension);
                    //Console.WriteLine(file.LastWriteTime);
                }
    

    UWDocs is an anchor with Runat="server"