Select Page

In this  Microsoft Azure article, we will create a storage container inside an Azure storage account using Azure SDK for .NET.

Estimated reading time: 3 minutes

Azure SDK for .NET allows us to use native C# code and create infrastructure resources on the Azure cloud platform.

Using .NET tools to manage Azure allows us to integrate Azure services with existing and new .NET applications.

The SDK also shorten the learning curve for developers looking to integrate and use .NET to build cloud-native applications or add services like storage, data and more to their applications.

Creating a Storage Container in Azure Using Azure SDK for .NET

This post will focus on creating a storage container inside an Azure storage account. We will start with the first infrastructure provision, which consists of a storage account using Azure PowerShell and Bicep.

Create Storage Account

We will use Azure PowerShell and the following commands to create a resource group and a storage account.

Once the resource group is ready, we will create a storage account using Bicep. Azure Bicep is an Azure-only Infrastructure-as-code(IaC) tool that allows us to programmatically provision infrastructure and services on Azure.

Bicep is similar to Terraform but only works on Azure, uses the latest Azure API, and stores the state files in Azure.

The following Bicep file contains the deployment file for a storage account.

To create the storage account, run the following commands.

Retrieve Storage Account Connection String Using PowerShell

Before we can access the storage account for our C# Console application, we need to retrieve the storage account’s connection string.

I will use the PowerShell script to retrieve the connection string from the storage account.

Copy the connection string and save it for the next section.

Create C# Console Application

To create a storage container on Azure, we must first create a console application and install the Azure SDK storage libraries.

Create an Environment Variable

To connect to the storage account, the console app needs the connection string details to authenticate to Azure.

Using the connection string we copied from the previous section, create an environment variable called connectionString, as shown below.

Console App Code

Copy the following code to your Program.cs file and run the application. The application will create a container with a random name of deploycontainers and today’s date.


Discover more from CPI Consulting Pty Ltd Experts in Cloud, AI and Cybersecurity

Subscribe to get the latest posts sent to your email.