How to read data from file residing in subfolder in azure data lake storage in .net core

DevBuster007 186 Reputation points
2021-11-04T06:27:56.393+00:00

I have a .net core application where i need to read data from ADLS file. Issue is file is residing in subfolders. For example- Container/Folder1/Folder2/File.json

I am using below code to get the filtered data:

        var connectionString = this.accessKey;
        var blobServiceClient = new BlobServiceClient(connectionString);
        var containerClient = blobServiceClient.GetBlobContainerClient("ods");

        await foreach (var blobItem in containerClient.GetBlobsAsync(BlobTraits.Metadata, BlobStates.None, "File Prefix"))
        {
            var blobClient = containerClient.GetBlockBlobClient(blobItem.Name);

            var options = new BlobQueryOptions
            {
                InputTextConfiguration = new BlobQueryJsonTextOptions(),
                OutputTextConfiguration = new BlobQueryJsonTextOptions()
            };

            var result = await blobClient.QueryAsync(@"SELECT * FROM BlobStorage WHERE measuringpointid = 547", options);

            var jsonString = await new StreamReader(result.Value.Content).ReadToEndAsync();

            Console.WriteLine(jsonString);
            Console.ReadLine();
        }
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.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.