Change Azure DataLake Gen2 file tier using C#

manish verma 216 Reputation points

HI All,

We have requirement in Azure Data Lake Gen2 to Change file tier from Hot to cool or Hot to Archive using C#

based on file name.

For Example- we have a file name "test.csv" - tier - hot, how can we move this file in cool tier using C#


Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
993 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
1,832 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
1,688 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,190 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 17,366 Reputation points Microsoft Employee

    Hi @manish verma ,

    Thanks for using Microsoft Q&A!!
    If I understand you correctly you want to change the tier of any specific file stored as a blob on Azure Data Lake Gen2 storage.

    In order to work with blob files stored on Azure Data Lake Storage Gen2, you need to use Azure Blob Storage .NET package as documented over here and changing the tier of any blob stored on a container require you to use SetAccessTier/SetAccessTierAsync method of BlobClient or BlockBlobClient based on your blob type. Please see the below code which you can use to change the tier -

                string containerName = "input";  
                string connectionString = $"DefaultEndpointsProtocol=https;AccountName={Account Name};AccountKey={Access Key};";  
                BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);              
                BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);  
                BlobClient bc = containerClient.GetBlobClient("movies.csv");  
                var result = await bc.SetAccessTierAsync(AccessTier.Cool);  

    Here, you can get the Connection String from Access Keys blade of Storage account.

    Additional documentation to know more about setting blobs tier is available at Setting or changing a blob's tier.

    Please let me know if you have any questions.



    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

  2. manish verma 216 Reputation points

    Thanks a lot for your replay. we will test and update you