How to Get (Retrieve) the Files from Azure Blob Storage Programmatically using C#

Sathish Nadarajan
 
Solution Architect
November 16, 2018
 
Rate this article
 
Views
10788

In the earlier articles, we saw how to upload files to the Blob Storage. In this article, let us see how to retrieve the files from the blob storage programmatically using C#.

The method is straight forward and we need the Connection string which can be obtained from the portal as below.

clip_image002

Out of the Key1 and Key2, get any one of the connection string.

The below method will get the blobs from the container

 public static void GetFilesFromBlob()
 
 {
 
 string storageConnectionString = "*********";
 
 // Retrieve storage account from connection string.
 
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
 
 // Create the blob client.
 
 CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
 
 // Retrieve reference to a previously created container.
 
 CloudBlobContainer container = blobClient.GetContainerReference("ContainerName");
 
 CloudBlobDirectory dira = container.GetDirectoryReference("FolderName");
 
 //Gets List of Blobs
 
 var list = dira.ListBlobs();
 
 List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
 
 }
 

We can process this blobs based on our requirements.

Happy Coding,

Sathish Nadarajan.

Category : Azure, Storage

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment