using Aliyun.OSS; using Aliyun.OSS.Common; using System; using System.Collections.Generic; namespace ConsoleApp5AliOSS { class Program { static void Main(string[] args) { // Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint = "https://oss-cn-shenzhen.aliyuncs.com"; // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。 String accessKeyId = "LTAI4FsANPbYKsxD6rWB8ShJ"; String accessKeySecret = "fxQ6VHiEQtwH3MjlGeCoCWYeViqzkA"; String bucketName = "hystkj-oss"; // 创建ClientConfiguration实例,按照您的需要修改默认参数。 var client = new OssClient(endpoint, accessKeyId, accessKeySecret); try { var objects = new List(); ObjectListing result = null; string nextMarker = string.Empty; do { var listObjectsRequest = new ListObjectsRequest(bucketName) { Marker = nextMarker, }; // 列举文件。 result = client.ListObjects(listObjectsRequest); foreach (var summary in result.ObjectSummaries) { Console.WriteLine(summary.Key); objects.Add(summary.Key); } nextMarker = result.NextMarker; } while (result.IsTruncated); Console.WriteLine("List objects of bucket:{0} succeeded ", bucketName); } catch (OssException ex) { Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); } catch (Exception ex) { Console.WriteLine("Failed with error info: {0}", ex.Message); } } } }