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();
}
}
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(); } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.