Introduction
I believe there are many articles or blogs already available which show how to convert an Excel file to a comma separated file using C# and in all the cases (which I referred to), Excel is read from a hard drive of a local machine and the CSV file is saved back to the same hard drive. But in spite of knowing this, again, I’m going to draft another post.
Wondering why?
Well, this post is going to be slightly different in the way files are being read and saved back. Below are the major offerings of this post:
- What if we have many Excel files to convert but the disk does not have enough space to save all of those? Same is the case for conversion output too.
- What if we don’t have permission to save our converted files on to the local machine?
- How can we run this conversion utility using web jobs?
In order to address the above challenges, we can utilize Azure capabilities wherein we will do everything on the fly without utilizing disk space as a storage for our files. Let’s see everything in action by going step by step.
Problem Statement
Read Excel files from Azure blob storage, convert them to CSV format and upload them back to Azure blob storage. This entire process has to run via triggered web job, so that it can be repeated as and when Excel to CSV conversion is required.
Setting Up Environment
I’m using Visual Studio 2019 v16.4.0 and have an active Azure subscription.
High Level Tasks
Below is the list of high level tasks which we will be performing:
- Creating containers in Azure storage
- Reading Excel from Azure storage
- Converting Excel to CSV format
- Uploading CSV to Azure storage
- Creating Azure WebJob
- Triggering Azure WebJob
Creating Containers in Azure Storage
A container must be created under blob service to store all the Excel files which need to be converted to CSV format. Now there are two ways one can create a container – one is through the Azure portal and another one is by using C#. As both these are easily available on MSDN, I’m not going to repeat the entire procedure. For detailed steps on how to create a container, please refer to the references section.
For our exercise, I’ve created two containers named excelcontainer and csvcontainer under one storage account, where,
- excelcontainer – holds Excel files which are to be converted to CSV
- csvcontainer – holds the converted CSV files
Below is the screenshot of my excelcontainer, which holds three Excel workbooks,

Reading Excel from Azure Storage
Now we have excelcontainer ready with uploaded files, it’s time to read data from all those files and here is the code to do that,
- public async Task<List<BlobOutput>> Download(string containerName)
- {
- var downloadedData = new List<BlobOutput>();
- try
- {
- // Create service and container client for blob
- BlobContainerClient blobContainerClient =
- _blobServiceClient.GetBlobContainerClient(containerName);
- // List all blobs in the container
- await foreach (BlobItem item in blobContainerClient.GetBlobsAsync())
- {
- // Download the blob's contents and save it to a file
- BlobClient blobClient = blobContainerClient.GetBlobClient(item.Name);
- BlobDownloadInfo downloadedInfo = await blobClient.DownloadAsync();
- downloadedData.Add(new BlobOutput
- { BlobName = item.Name, BlobContent = downloadedInfo.Content });
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return downloadedData;
- }
Where BlobOutput is the DTO with the below members,
- public class BlobOutput
- {
- public string BlobName { get; set; }
- public Stream BlobContent { get; set; }
- }

Join the conversation! Your thoughts help the community grow.