List S3 Bucket keys in a listview winform c#

Viewed 175

So I'm trying to list the files in my S3 bucket to my winform in visual studio c#

static async Task ListingObjectAsync()
{
    try
    {
        ListObjectsV2Request request = new ListObjectsV2Request
        {
            BucketName = bucketName
        };
        ListObjectsV2Response response;
        do
        {
            response = await s3Client.ListObjectsV2Async(request);

            foreach (S3Object entry in response.S3Objects)
            {
                string file = entry.Key;
                ListViewItem item = new ListViewItem(file);
                listView1.Items.Add(item);
            }
        } while (response.IsTruncated);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
   
}

But it says that "an object reference is required for a non static field"

Any tips on how to list files from S3 bucket to listview, datagrid or other forms?

Thank you! P.S. I'm new to stack overflow so I'm sorry if my question format is wrong

1 Answers

remove the static from your method declaration:

async Task ListingObjectAsync(){...}

you cannot access instance variables from a static method

Related