Delete folder using Microsoft.WindowsAzure.Storage.Blob : blockBlob.DeleteAsync();

576 Views Asked by At

I am using C# in an Azure HTTP Trigger to remove an empty blob storage child folder. I have obtained the URI of the child folder and setup the security token access to the storage.

However, when I invoke the method:

blockBlob.DeleteAsync();

While this is successful, the folder is not removed?

Is there a better mechanism for removing a blob folder (that does not get removed when empty) using .NET C# approach?

Should I be passing parameters and invoking a different version of this method?

1

There are 1 best solutions below

3
On BEST ANSWER

Considering hierarchical namespace is enabled for the storage account, the SDK you would want to use is Azure.Storage.Files.DataLake.

To delete a directory, your code would be something like (taken from here):

public void DeleteDirectory(DataLakeFileSystemClient fileSystemClient)
{
    DataLakeDirectoryClient directoryClient =
        fileSystemClient.GetDirectoryClient("my-directory");

    directoryClient.Delete();
}