I am getting a list of files hosted in Azure and attempting to delete them.
var blobList = container.ListBlobs(prefix: "/2017/1/", useFlatBlobListing:true);
foreach (var blob in blobList)
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blob.Uri.ToString());
blockBlob.Delete(); // This line causes a 404 not found exception.
}
When I debug and step through the code the blob.Uri matches the folder structure in Azure so not sure why this exception occurs.
Edit: Found an answer - I have to check the type and box appropriately
foreach (var item in blobList)
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blob.Delete();
}
}