Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (13.1k points)
I have an azure blob storage which contains many json files which i want to read from my blobstorage so that i can able to perform some operations in it.

How can i able to actually read all of my files from azure blob storage??

1 Answer

0 votes
by (26.7k points)

In order to access or read files from your microsoft azure blob storage you must have a storage account connection string, your container name and file name of whatever files present inside your blob container. Also you need to have a NuGet package as well :

Windows.Azure.Storage

After that go through this code.

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Blob;

public string GetBlob(string containerName, string fileName)

{

  string connectionString = $"yourconnectionstring";

  // Setup the connection to the storage account

  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

   

  // Connect to the blob storage

  CloudBlobClient serviceClient = storageAccount.CreateCloudBlobClient();

  // Connect to the blob container

  CloudBlobContainer container = serviceClient.GetContainerReference($"{containerName}");

  // Connect to the blob file

  CloudBlockBlob blob = container.GetBlockBlobReference($"{fileName}");

  // Get the blob file as text

  string contents = blob.DownloadTextAsync().Result;

   

  return contents;

}

Execution :

GetBlob("containername", "my/file.json");

Want to be an Azure Expert ? Join Azure Certification

Browse Categories

...