Skip to Content
C# 8 and .NET Core 3 Projects Using Azure - Second Edition
book

C# 8 and .NET Core 3 Projects Using Azure - Second Edition

by Paul Michaels, Dirk Strauss, Jas Rademeyer
December 2019
Intermediate to advanced
528 pages
11h 19m
English
Packt Publishing
Content preview from C# 8 and .NET Core 3 Projects Using Azure - Second Edition

Using the Azure Storage Client

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Enterprise Application Development with C# 9 and .NET 5

Enterprise Application Development with C# 9 and .NET 5

Ravindra Akella, Rishabh Verma, Arun Kumar Tamirisa, Suneel Kumar Kunani, Bhupesh Guptha Muthiyalu
ASP.NET Core 2 and Angular 5

ASP.NET Core 2 and Angular 5

Valerio De Sanctis, Jürgen Gutsch
ASP.NET Core 5 for Beginners

ASP.NET Core 5 for Beginners

Andreas Helland, Vincent Maverick Durano, Jeffrey Chilberto, Ed Price

Publisher Resources

ISBN: 9781789612080Supplemental Content