We'll start by uploading a file into Azure Storage. The first step is to download the NuGet package for client access to Azure Storage:
Install-Package WindowsAzure.Storage
Then, we can create the method to upload the file:
public async Task UploadFile(string fullPath)
{
string fileName = Path.GetFileName(fullPath);
var blob = GetBlockBlobReference(fileName);
using (var fileStream = System.IO.File.OpenRead(fullPath))
{
await blob.UploadFromStreamAsync(fileStream);
}
}
The preceding code is basically getting a reference to the file in Azure (even though it doesn't exist) and uploading the stream. We should probably have a look at the helper method, that is, GetBlockBlobReference:
private CloudBlockBlob GetBlockBlobReference(string fileName)
{
if (CloudStorageAccount.TryParse(_connectionString, out CloudStorageAccount...