question

manishverma-7371 avatar image
0 Votes"
manishverma-7371 asked SaurabhSharma-msft commented

Change Azure DataLake Gen2 file tier using C#

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

dotnet-csharpazure-storage-accountsazure-blob-storageazure-data-lake-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered SaurabhSharma-msft commented

Hi @manishverma-7371,

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.



image.png (50.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @manishverma-7371,
Please let me know if you find above reply useful. If yes, please 'Accept the answer' for the above reply. This will help other community members facing similar query to refer to this solution. Thanks.

Thanks
Saurabh

0 Votes 0 ·
manishverma-7371 avatar image
0 Votes"
manishverma-7371 answered SaurabhSharma-msft commented

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


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @manishverma-7371,

I have not heard back from you. Did my answer solve your issue? If so, please mark as accepted answer. If not, please let me know how I may better assist.

Thanks
Saurabh

0 Votes 0 ·