A bucket is a container used to store objects in Object Storage Service (OSS). Every object is contained in a bucket. This topic describes how to determine whether a bucket exists.

Sample code

The following code provides an example on how to determine whether a specific bucket exists:

using Aliyun.OSS;

// Initialize an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

// Determine whether the bucket exists. 
public void DoesBucketExist(string bucketName)
        var exist = client.DoesBucketExist(bucketName);

        Console.WriteLine("Check object Exist succeeded");
        Console.WriteLine("exist ? {0}", exist);
    catch (Exception ex)
        Console.WriteLine("Check object Exist failed. {0}", ex.Message);


For the complete sample code for determining whether a bucket exists, visit GitHub.