Delete temporary blob files on the web (.NET environment)

 

Abstract 

To implement the uploading of blob fields on the web, temporary directories are used to save the file to the server’s disk first and then upload it to the database

Detailed description 

 

The directories are specified using the Blob Local Storage Path and Temp Media Directory model properties. To have the files automatically deleted, in Upgrade 3 you can create a global.asax file and save it to the application directory.

The file must contain the following code:

<%@ Import namespace=”System.IO” %>
<Script language=”C#” runat=”server”>

public void Application_OnStart()
{
Application[“TemporaryFilesToDelete”]= new ArrayList();
}
public void Application_OnEnd()
{
ArrayList toDelete = (ArrayList)(Application[“TemporaryFilesToDelete”]);
foreach( string fileName in toDelete)
File.Delete( fileName);
}
</script>

This way the files will be deleted when the application’s memory usage exceeds the configured maximum or according to the recycling configuration. That is to say, when the process (Aspnet_wp or W3wp) is recycled, it deletes all the files that have been created since the application was started (and that haven’t been deleted after ending a session).

WARNING: This implementation has a high startup cost, which is an obstacle for prototyping. It implies that the person who executes the first request after restarting the process serving the web objects (w3wp or aspnet_wp) must run this deletion and therefore delay the request.

 

One thought on “Delete temporary blob files on the web (.NET environment)

  1. Didn’t work?
    Try this one:

    Create a “*.bat” file with the follwing:

    Forfiles /P “path_to file” /D -1 /S /C “Cmd /C del @FILE”

    And run it through the Task Schedule Wizard to run everyday.
    This is going to delete all files older than 1 day

    Enjoy

Leave a Reply

Your email address will not be published. Required fields are marked *