Using Wisej.NET to Access Blob Storage with Microsoft Azure
Last updated
Was this helpful?
Last updated
Was this helpful?
This document describes how you can benefit from using Azure files in your .NET web application.
During a web-enabling process, one of our standard tasks that we analyze with our customers revolves around file management. Our experience has proven that desktop applications heavily use file manipulation, therefore we need to provide modern options to support this feature within web-enabled applications.
Wisej.NET Framework is very flexible and extensible when it comes to file handling. It provides an abstract interface for file access enabling customers to use any file system that their web applications need: either the built-in default implementation for the standard disk-based file system or several alternative implementations for cloud-based file storage.
Nowadays, it is attractive to deploy web applications to an environment like Microsoft Azure. Therefore, it makes sense to use an Azure file integration as a supplement or total replacement for traditional on-premise file servers.
In this article, I am describing the way a Wisej.NET web application can interact with cloud files stored on Microsoft Azure Blob Storage. To connect your web application to Azure Blob Storage, there are a couple of easy steps to follow.
Azure subscription
Azure storage account
Install Azure.Storage.Blobs
12.10 library in your solution:
Install System.Runtime.CompilerServices.Unsafe
version 4.6.0:
The Compiler Services will require a binding redirect in the Web.config file:
Install System.Buffers
version 4.5.1:
The System.Buffers
will require a binding redirect in the Web.config file:
The file system implementation for the Azure Blob storage needs to be placed in a class that implements the Wisej.NET IFileSystemProvider
, I named my new class AzureBlobProvider
:
The authentication to the Blob storage can be done in many ways like the Microsoft documentation indicates – the actual authentication is not in the current scope of this article, but rather the file access part is more relevant. Independent of the authentication type, for the actual Azure Blob storage connection, we need to know the account and container name – which is stored in our AzureBlobProvider
class members:
Scenario 1: Import Operation
For a standard import operation, the end user should be able to select the file path from the Azure storage. To achieve the file import, I have used a Wisej.NET Open File Dialog where I added both a local folder and an Azure Blob storage container just to show case that both file systems can be used together:
If we run the sample, the user is prompted with a file picker dialog – as shown, the Azure Blob Storage folder structure is displayed:
This is possible because the Wisej.NET Open File Dialog calls GetDirectories
and GetFiles
methods from our AzureBlobProvider
class:
For displaying the file properties, the AzureBlobProvider
class implements methods like GetFileSize
or GetCreationTime
.
After the user selects the imported file, the web application may require processing the file content. On the server side, this operation means downloading the Azure Blob item and reading its content.
The implementation for downloading and reading a Blob item’s content is here:
Scenario 2: Export Operation
Another common scenario is when the web application is generating a report which should be uploaded to either a pre-defined or a user-defined Azure location. To simulate the export, in my sample, you can type in the file content and then click the Upload button:
After clicking the Upload button, the Save File Dialog allows you to specify the location and the name of your file:
The result will be uploaded in Azure Storage:
Wisej.NET is a very powerful web application framework which enables taking advantage of the latest .NET technologies.
For further examples on how to implement cloud storage file access, I recommend the Amazon S3 file system implementation provided by ITG, which was also my support for developing the Azure Storage file system provider.
wisej-extensions · iceteagroup/wisej-extensions (github.com)