Recommended way of automatically scheduling cleanup of temporary download files from Azure Web App

Axium 20 Reputation points
2024-11-28T22:26:15.8666667+00:00

Hello Microsoft Community,

I allow users to download excel files from my Azure Web App. The files are created at runtime and once they are downloaded they can be deleted from the Web Server.

The files are stored in \wwwroot\exportfiles. I would like to delete the \exportfiles folder every Sunday at 4 am. (Note, if the folder does not exist I recreate it at runtime.)

The Web App is built using .Net 9 and Blazor Server Side.

What is the recommended way of doing this with an Azure Web App?

Thank you.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,000 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 22,156 Reputation points Microsoft Employee
    2024-11-29T06:42:51.3933333+00:00

    @Axium Thanks for posting your questions.

    Based on shared information I understand that you want to delete specific files under \site\wwwroot on weekly basis.

    You can leverage the triggered webjobs (runs based on schedule using CRON expression) in app service which are designed to run the background jobs.

    Here is the CRON expression to run the job on every Sunday at 4AM 0 0 4 * * 0

    If you are webapp is running on windows runtime you can use the below PowerShell script to delete the specific exported files.

    cd C:\home\site\wwwroot
    Remove-Item .\export* -recurse
    

    If your webapp is running on Linux runtime then use the below script ion you web job.

    cd /home/site/wwwroot
    rm -rf ./export*
    

    To know more information about web jobs you can refer to this documentation.

    Also note that WebJobs for Windows container, Linux code, and Linux container is in preview. WebJobs for Windows code is generally available and not in preview.

    Hope this help, let me know if you have any further questions on this.

    Please accept as "Yes" if the answer is helpful so that it can help others in the community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.