Skip to content

Instantly share code, notes, and snippets.

@SeanDrum
Created April 24, 2021 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanDrum/8e7f7387f0aa5e1a9f9d435ea27b4947 to your computer and use it in GitHub Desktop.
Save SeanDrum/8e7f7387f0aa5e1a9f9d435ea27b4947 to your computer and use it in GitHub Desktop.
A simple example of how to download all files in a Azure Blob Container using a SAS Auth Method
using System;
using System.Configuration;
using System.IO;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
namespace AzureBlobDownload
{
class AzureBlobDownload
{
static async Task Main()
{
string uriString = ConfigurationManager.AppSettings.Get("SasUri");
string localDownloadPath = ConfigurationManager.AppSettings.Get("LocalDownloadPath");
Uri sasUri = new Uri(uriString);
BlobContainerClient blobContainerClient = new BlobContainerClient(sasUri);
await foreach (BlobItem blob in blobContainerClient.GetBlobsAsync())
{
string fileName = blob.Name;
string localFilePath = Path.Combine(localDownloadPath, fileName);
using (var file = File.Open(localFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
var blobClient = blobContainerClient.GetBlobClient(blob.Name);
await blobClient.DownloadToAsync(file);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment