I would like to add old blobs to a list and then loop through it and delete them.
So if 7 days have passed since the blob was last modified i want to delete it. Blobs got a property named last modified, but it seems like its of type bool (?)
Anyone been down this road before?
Something like this:
CloudBlobContainer container = CloudStorageServices.GetCloudBlobsContainer();
var blobs = container.ListBlobs().OfType<CloudBlockBlob>().Where(b=>b.Properties.LastModified - b.Properties.LastModified.AddDays(7)).TotalHours <= 0);
Thanks!
You're more or less on the right path. Try the code below. It will fetch the blobs from a container which have not been modified in last 7 days.
static void GetOldBlobs()
{
CloudStorageAccount acc = new CloudStorageAccount(new StorageCredentials("account name", "account key"), false);
var client = acc.CreateCloudBlobClient();
var container = client.GetContainerReference("container name");
var blobs = container.ListBlobs("", true).OfType<CloudBlockBlob>().Where(b => (DateTime.UtcNow.AddDays(-7) > b.Properties.LastModified.Value.DateTime)).ToList();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With