Introduction

This article will help you learn the process of creation of an Azure Blob Storage using Visual Studio.

This article will cover the following.

Before reading this article, please go through some important articles mentioned below.

Azure Storage

Azure Storage is one of the cloud computing PaaS (Platform as a Service) services provided by the Microsoft Azure team. It provides cloud storage that is highly available, secure, durable, scalable, and redundant. It is massively scalable and elastic. It can store and process hundreds of terabytes of data or you can store the small amounts of data required for a small business website.

What is Blob?

Blob is a service for storing large amounts of unstructured data that can be accessed from anywhere in the world via HTTP or HTTPS." Blob stands for " Binary Large Object ". It's designed to store large amounts of unstructured text or binary data like virtual hard disks, videos, images or even log files. The data can be exposed to the public or stored privately. It scales up or down as your needs change. We no longer manage it, we only pay for what we use.

Create Blob Storage using Visual Studio.

Prerequisites

Follow the below steps to create an Azure Storage Account.

Step 1

Log in here. Please go through the article mentioned below for creating a Storage account mentioned below.

After creating the storage account, navigate to the Access key and then copy the key & connection string.

Creating Blob Storage Using Visual Studio

Step 2 - Create a container in Visual studio

Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio

Step 4 –Install NuGet Package

Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio

Step 5 – App Configuration

Creating Blob Storage Using Visual Studio
  1. <appSettings>
  2. <add key="StorageConnection" value="YOUR-CONNECTION-STRING-COPIED-FROM-EARLIER"/>
  3. </appSettings>

Step 6 – Create Container

Creating Blob Storage Using Visual Studio
Creating Blob Storage Using Visual Studio
  1. string storageConnection = CloudConfigurationManager.GetSetting("BlobStorageConnectionString");
  2. // CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));
  3. CloudStorageAccount storageAccount = new CloudStorageAccount(
  4. new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("Storagename","Key"), true);
  5. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  6. CloudBlobContainer container = blobClient.GetContainerReference("image");
  7. container.CreateIfNotExists(BlobContainerPublicAccessType.Container);
  8. Console.ReadKey();
Output

This code will get our connection string from the App.config, and create a container named images if it doesn’t exist in the portal. We can go back inside of the portal to see if executed correctly.

Creating Blob Storage Using Visual Studio

Step 7 – Uploading Blob

Creating Blob Storage Using Visual Studio

Output

If we switch over to our Storage Account and navigate inside the container, we’ll see our new file has been added.

Creating Blob Storage Using Visual Studio

Open the file

Creating Blob Storage Using Visual Studio

Step 8 – Download Blob

Creating Blob Storage Using Visual Studio
  1. using (var fileStream = System.IO.File.OpenWrite(@"D:\Azure-new.png"))
  2. {
  3. blockBlob.DownloadToStream(fileStream);
  4. }

Output

Now we are using the OpenWrite method and specifying a new name. So we are also taking advantage of the DownloadToStream method. If we run the application, our new file should be in the specified folder.

Creating Blob Storage Using Visual Studio

Summary

I hope you understood how to create an Azure Blob Storage using Visual Studio. Stay tuned for more Azure Storage.