Transfer objects to and from Azure Blob Storage using .NET
This repository contains a sample project to help you get started using Azure Storage with .NET Core and C# as the development language.
To complete this tutorial:
If you don't have an Azure subscription, create a free account before you begin.
Create a storage account using the Azure portal
First, create a new general-purpose storage account to use for this quickstart.
- Go to the Azure portal and log in using your Azure account.
- On the Hub menu, select New > Storage > Storage account - blob, file, table, queue.
- Enter a unique name for your storage account. Keep these rules in mind for naming your storage account:
- The name must be between 3 and 24 characters in length.
- The name may contain numbers and lowercase letters only.
- Make sure that the following default values are set:
- Deployment model is set to Resource manager.
- Account kind is set to General purpose.
- Performance is set to Standard.
- Replication is set to Locally Redundant storage (LRS).
- Select your subscription.
- For Resource group, create a new one and give it a unique name.
- Select the Location to use for your storage account.
- Check Pin to dashboard and click Create to create your storage account.
After your storage account is created, it is pinned to the dashboard. Click on it to open it. Under Settings, click Access keys. Select the primary key and copy the associated Connection string to the clipboard, then paste it into a text editor for later use.
Put the connection string in an environment variable
This solution requires a connection string be stored in an environment variable securely on the machine running the sample. Follow one of the examples below depending on your Operating System to create the environment variable. If using windows close out of your open IDE or shell and restart it to be able to read the environment variable.
setx storageconnectionstring "<yourconnectionstring>"
At this point, you can run this application. It creates its own file to upload and download, and then cleans up after itself by deleting everything at the end.
Run the application
Navigate to your directory where the project file (.csproj) resides and run the application with the
dotnet run command.
The Azure storage documentation includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.