{"id":129,"date":"2009-04-02T09:13:46","date_gmt":"2009-04-02T14:13:46","guid":{"rendered":"http:\/\/www.1oc.com\/blog\/?p=129"},"modified":"2009-04-02T09:13:46","modified_gmt":"2009-04-02T14:13:46","slug":"delete-temporary-blob-files-on-the-web-net-environment","status":"publish","type":"post","link":"http:\/\/blog.1oc.com\/?p=129","title":{"rendered":"Delete temporary blob files on the web (.NET environment)"},"content":{"rendered":"<p>\u00a0<\/p>\n<p><strong>Abstract\u00a0<\/strong><\/p>\n<p>To implement the uploading of blob fields on the web, temporary directories are used to save the file to the server&#8217;s disk first and then upload it to the database<\/p>\n<p><strong>Detailed description\u00a0<\/strong><\/p>\n<p>\u00a0<\/p>\n<p>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.<\/p>\n<p>The file must contain the following code:<\/p>\n<p>&lt;%@ Import namespace=&#8221;System.IO&#8221; %&gt;<br \/>\n&lt;Script language=&#8221;C#&#8221; runat=&#8221;server&#8221;&gt;<\/p>\n<p>public void Application_OnStart()<br \/>\n{<br \/>\nApplication[&#8220;TemporaryFilesToDelete&#8221;]= new ArrayList();<br \/>\n}<br \/>\npublic void Application_OnEnd()<br \/>\n{<br \/>\nArrayList toDelete = (ArrayList)(Application[&#8220;TemporaryFilesToDelete&#8221;]);<br \/>\nforeach( string fileName in toDelete)<br \/>\nFile.Delete( fileName);<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<p>This way the files will be deleted when the application&#8217;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&#8217;t been deleted after ending a session).<\/p>\n<p>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.<\/p>\n<div><\/div>\n<p>\u00a0<\/p>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Abstract\u00a0 To implement the uploading of blob fields on the web, temporary directories are used to save the file to the server&#8217;s disk first and then upload it to the database Detailed description\u00a0 \u00a0 The directories are specified using &hellip; <a href=\"http:\/\/blog.1oc.com\/?p=129\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-genexus"],"_links":{"self":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=129"}],"version-history":[{"count":0,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}