Azure Blobs from C# and Visual Studio – C# Advent Calendar

This blog post is part of the The Second Annual C# Advent by Matthew Groves which is a C# advent calendar of blog posts by the community which uses C# to cover a topic of your choosing – I chose to show how to use Azure Blob Storage from C# and created a simple console application to upload images from a folder on your local computer and push the images into Azure Blob Storage.

To see all of the other blog posts for the C# advent calendar take a look here

The sample code for this blog post can be found on github

The following will show you how to create and access blobs using C#

  • Log into your Azure account or create a free one
  • Create a new Resource Group and call it something like BlobStorageCSharp
  • Next Add a new Resource, and search for Storage and then select the following highlighted Storage account – blob, file, table, queue)

The code example will show how to create a container which will upload the images into a container in blob storage up into your Azure storage account.

The code makes use of Azure Blob Storage from C# to create a public blob storage container called xmasimages-container if it doesn’t exist already making use of the following:-

And then upload images found in a folder on your local machine and stores the images into the public blob storage container.

You can read more on blob storage container’s and using C# to work with Azure storage

Once the images have been uploaded you could use Azure Storage explorer to view them.

Once you have downloaded and ran the code from my repo above, open up storage explorer and follow the steps below:-

  • Sign into your Azure Subscription
  • Expand Storage Account
  • Expand Blob Containers
  • Locate your container (xmasimages-container)
  • Highlight an image on the right hand side
  • Click Download or double-click and open it using any image viewer.
  • Viola – you’ve uploaded images and now you can view them

It’s a simple demo and there is a lot more you could continue with, so go grab the code, modify and extend it by doing some of the following: –

  • Change the code to make use of Azure Key Vault to store the connection string to your blob storage container
  • Extend the code to list the files within your container

Thanks to Matt Groves for doing the C# advent calendar, mind and check all the other great content here.

Merry Christmas and enjoy!
Gregor

 

4 thoughts on “Azure Blobs from C# and Visual Studio – C# Advent Calendar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s