All Products
Search
Document Center

Object Storage Service:Manage symbolic links (C# SDK V2)

Last Updated:Mar 20, 2026

A symbolic link points to a target object in a bucket. Use it to access the object through the link name, without knowing its actual path. This topic describes how to use the OSS C# SDK V2 to create and get symbolic links.

Prerequisites

Before you begin, ensure that you have:

  • The oss:PutObject permission to create a symbolic link

  • The oss:GetObject permission to get a symbolic link

For details on granting permissions, see Grant custom access policies to RAM users.

Usage notes

  • The sample code uses the China (Hangzhou) region (cn-hangzhou) and a public endpoint by default. If you access OSS from another Alibaba Cloud product in the same region, use an internal endpoint. For endpoint details, see OSS regions and endpoints.

Create a symbolic link

Use PutSymlinkAsync to create a symbolic link that points to a target object.

using OSS = AlibabaCloud.OSS.V2;  // Alias for the OSS SDK namespace.

var region = "cn-hangzhou";        // Required. The region where the bucket is located.
var endpoint = null as string;     // Optional. Override the default endpoint, e.g., https://oss-cn-hangzhou.aliyuncs.com.
var bucket = "<your-bucket-name>"; // Required. The bucket name.
var key = "<your-object-name>";    // Required. The name of the target object.
var target = "<your-symlink-name>";// Required. The name of the symbolic link.

// Initialize the SDK configuration. Credentials are read from environment variables:
// OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
var cfg = OSS.Configuration.LoadDefault();
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
cfg.Region = region;
if (endpoint != null)
{
    cfg.Endpoint = endpoint;
}

using var client = new OSS.Client(cfg);

// Create the symbolic link.
var result = await client.PutSymlinkAsync(new()
{
    Bucket = bucket,
    Key = key,
    SymlinkTarget = target,
});

Console.WriteLine("PutSymlink done");
Console.WriteLine($"StatusCode: {result.StatusCode}");
Console.WriteLine($"RequestId: {result.RequestId}");

For the complete sample, see PutSymlink.cs.

Get a symbolic link

Use GetSymlinkAsync to retrieve the target object that a symbolic link points to. The key return value is SymlinkTarget.

using OSS = AlibabaCloud.OSS.V2;  // Alias for the OSS SDK namespace.

var region = "cn-hangzhou";        // Required. The region where the bucket is located.
var endpoint = null as string;     // Optional. Override the default endpoint, e.g., https://oss-cn-hangzhou.aliyuncs.com.
var bucket = "<your-bucket-name>"; // Required. The bucket name.
var key = "<your-symlink-name>";   // Required. The name of the symbolic link.

// Initialize the SDK configuration. Credentials are read from environment variables:
// OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
var cfg = OSS.Configuration.LoadDefault();
cfg.CredentialsProvider = new OSS.Credentials.EnvironmentVariableCredentialsProvider();
cfg.Region = region;
if (endpoint != null)
{
    cfg.Endpoint = endpoint;
}

using var client = new OSS.Client(cfg);

// Get the symbolic link.
var result = await client.GetSymlinkAsync(new()
{
    Bucket = bucket,
    Key = key,
});

// SymlinkTarget is the target object that this symbolic link points to.
Console.WriteLine($"SymlinkTarget: {result.SymlinkTarget}");
Console.WriteLine($"StatusCode: {result.StatusCode}");
Console.WriteLine($"RequestId: {result.RequestId}");

For the complete sample, see GetSymlink.cs.