Help Center> Object Storage Service> SDK Reference> .NET> Bucket Management> Identifying Whether a Bucket Exists

Identifying Whether a Bucket Exists

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

You can call ObsClient.HeadBucket to identify whether a bucket exists. Sample code is as follows:

// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// Identify whether a bucket exists.
try
{
    HeadBucketRequest request = new HeadBucketRequest
    {
        BucketName = "bucketname",
    };
    bool exists = client.HeadBucket(request);
    Console.WriteLine("Bucket exists: {0}", exists);
}
catch (ObsException ex)
{
    Console.WriteLine("StatusCode: {0}", ex.StatusCode);
}