Skip to content

Instantly share code, notes, and snippets.

@markusjohnsson
Created March 16, 2016 14:18
Show Gist options
  • Save markusjohnsson/e9d09d78ca9ee7c9190e to your computer and use it in GitHub Desktop.
Save markusjohnsson/e9d09d78ca9ee7c9190e to your computer and use it in GitHub Desktop.
Setting a property (CacheControl) to all blobs in a Azure blob storage container
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Linq;
namespace SetNoCache
{
class Program
{
static void Main(string[] args)
{
var blobConectionString = "<connectionstring>";
CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(blobConectionString);
var backupBlobClient = backupStorageAccount.CreateCloudBlobClient();
var backupContainer = backupBlobClient.GetContainerReference("<container>");
foreach (var blob in backupContainer.ListBlobs(useFlatBlobListing: true).OfType<CloudBlockBlob>())
{
blob.Properties.CacheControl = "no-cache";
blob.SetProperties();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment