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.
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.
Leave a comment