This article demonstrates how to delete blob items using Azure Function. To implement this, we will create a timer trigger Azure function which will periodically look at the container and delete blob items.
Prerequisites
- Basic Knowledge on Azure Function.
- Azure storage account already created.
- .NET Core SDK 3.1 installed in your PC.
- Azure storage emulator installed.
Create Time Trigger Function From Visual Studio
First, we will create Azure Function app empty project from visual studio. Give a solution name and project name as per your wish. Here, I have given project name as "AzFunctions".


Select Empty template here.

Once newly created solution is loaded, right click on function project => Click on Add => Click on New Azure Function… => Give function name as “DeleteBlobTimerTriggerFunc.cs” => Click on Add => Select “Timer Trigger” => Click on OK.
Install required NuGet packages into the function app project. For that, right click on the project => Click on Manage NuGet Packages… => Browse and install one by one.
- Microsoft.Azure.WebJobs
- Azure.Storage.Blobs
Add additional parameter into function. Run method as ExecutionContext which will give the possibility to use of ConfigurationBuilder so that Azure function can read storage connection string from JSON file or from function configuration settings on Azure.
Below sequential actions will be performed by this function,
- Read configuration values.
- Get BlobContainerClient reference based on the storage account connection string and container name (here container name is “dummy-messages”).
- Get All blobs and delete blob item one by one if exists.
DeleteBlobTimerTriggerFunc.cs
- using System;
- using Azure.Storage.Blobs;
- using Azure.Storage.Blobs.Models;
- using Microsoft.Azure.WebJobs;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- namespace AzFunctions
- {
- public static class DeleteBlobTimerTriggerFunc
- {
- [FunctionName("DeleteBlobTimerTriggerFunc")]
- public static void Run([TimerTrigger("%TimerSchedule%")] TimerInfo myTimer,
- ILogger log,
- ExecutionContext context)
- {
- log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
- var config = new ConfigurationBuilder()
- .SetBasePath(context.FunctionAppDirectory)
- .AddJsonFile("local.settings.json", true, true)
- .AddEnvironmentVariables().Build();
- BlobContainerClient blobContainerClient =
- new BlobContainerClient(config["CloudStorageAccount"], "dummy-messages");
- var blobs = blobContainerClient.GetBlobs();
- foreach (BlobItem blobItem in blobs)
- {
- blobContainerClient.DeleteBlobIfExistsAsync(blobItem.Name);
- log.LogInformation($"Blob Name {blobItem.Name} is deleted successfully.");
- }
- }
- }
- }




Join the conversation! Your thoughts help the community grow.