Sample C# Code For Accessing Storage Accounts
Intro
This page has information on C# code for accessing Azure Storage Accounts.
A lot of the examples here come from Microsoft's "Store application data with Azure Blob storage" training course.
Code is available here:
Get Code From GitHub
git clone https://github.com/MicrosoftDocs/mslearn-store-data-in-azure.git
Step-By-Step Guide
- Add a reference to the application's project to use Azure's Storage SDK and download that NuGet package.
Add SDK And Download Package
dotnet add package WindowsAzure.Storage dotnet restore
- To use the classes in that package, you must include them in your C# program.
Use Storage Classes
using Microsoft.WindowsAzure.Storage;
- Instantiate the storage account and parse the connection string (which contains the access keys to the storage account).
Storage Account Initialization
public Task Initialize(){ CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConfig.ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(storageConfig.FileContainerName); return container.CreateIfNotExistsAsync(); }
Related Articles
Filter by label
There are no items with the selected labels at this time.
- Microsoft's "Store application data with Azure Blob storage"