0

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();
    }
}
2
  • 4
    Can you make the last part an answer? Commented May 12, 2017 at 23:21
  • 2
    Echoing what @EJoshuaS stated: don't place your solution in the question. Place it in its own answer. This way, this question can be properly closed out. Commented May 13, 2017 at 4:12

1 Answer 1

1

The op wrote:

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();
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.