Enumerate Azure Storage File Share files with the .NET Azure SDK
This is a quick one. I recently had to enumerate an Azure Storage File Share with unknown files and directories so I quickly put together this .NET Core Console solution using the latest .NET Azure SDK. You can find more info on the latest and coolest Azure SDKs here.
Kudos to Jon Gallant (Azure SDKs team) for pointing me to the right/latest Azure SDK. It made my life so much easier and the code is more than half than the previous version.
Start by creating a new console app and adding the Azure.Storage.Files.Shares
NuGet package. Open the command line, navigate to your usual project folder and type the following:
mkdir azureDemo && cd azureDemo
dotnet new console
Wait for the project to be created and then add the necessary NuGet package:
dotnet add package Azure.Storage.Files.Shares
Once the package is restored, open Visual Studio or Visual Studio Code and add the following code:
You will need to add the appropriate references as per the gist sample (VS or VS Code IntelliSense should prompt you for these anyway):
using Azure.Storage.Files.Shares;
using Azure.Storage.Files.Shares.Models;
using System.Collections.Generic;
Finally, you'll need to make sure to update the inline connection string with your storage account name and the SAS Uri which should look like this:
"FileEndpoint=https://<YourStorageAccountName>.file.core.windows.net/;SharedAccessSignature=sv=2018-03-28&ss=f&srt=sco&sp=rl&se=2022-03-29T03:16:58Z&st=2019-03-28T19:16:58Z&spr=https&sig=SHtaaaaaaaaaaaaaaaaaaaaaaaaab3cY3lhFIo%3D"
That's all for today....