Change Azure DataLake Gen2 file tier using C#

manish verma 421 Reputation points
2022-04-02T07:03:27.327+00:00

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#

thanks

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.
1,356 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.
2,722 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,449 questions
C#
C#
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.
10,308 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Saurabh Sharma 23,751 Reputation points Microsoft Employee
    2022-04-04T23:37:56.72+00:00

    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};EndpointSuffix=core.windows.net";  
                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.
    189877-image.png

    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.

    Thanks
    Saurabh

    ----------

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


  2. manish verma 421 Reputation points
    2022-04-08T04:35:54.71+00:00

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