C# 如何从asp.net web api中删除Azure blob?

C# 如何从asp.net web api中删除Azure blob?,c#,asp.net-web-api,azure-storage-blobs,C#,Asp.net Web Api,Azure Storage Blobs,将图像从我的web api上载到azure blob存储可以正常工作,尽管在尝试删除图像时,我遇到以下错误: “Microsoft.WindowsAzure.Storage.StorageException”类型的异常发生在Microsoft.WindowsAzure.Storage.dll中,但未在用户代码中处理” 这是我使用的代码: // Retrieve storage account from connection string. CloudStorageAccount storageA

将图像从我的web api上载到azure blob存储可以正常工作,尽管在尝试删除图像时,我遇到以下错误: “Microsoft.WindowsAzure.Storage.StorageException”类型的异常发生在Microsoft.WindowsAzure.Storage.dll中,但未在用户代码中处理”

这是我使用的代码:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob.txt".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob.txt");

// Delete the blob.
 blockBlob.Delete();
我尝试使用的代码来自:


非常感谢任何帮助或意见,谢谢

您应该确保文件名或容器名正确。 我使用两种方法。我确信这两种方法都有效

你们能试试下面这行代码吗

var result= blockBlob.DeleteIfExists();

也许您应该查看异常并尝试解释它。公布结果。你能给我们完整的跟踪吗?