我正在获取Azure中托管的文件列表并尝试删除它们。
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.
}
当我调试并逐步执行代码时,blob.Uri与Azure中的文件夹结构匹配,因此不确定为什么会发生此异常。
编辑:找到答案 - 我必须适当检查类型和方框
foreach (var item in blobList)
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blob.Delete();
}
}
答案 0 :(得分:1)
操作写道:
编辑:找到答案 - 我必须适当检查类型和方框
foreach (var item in blobList) { if (item.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)item; blob.Delete(); } }