Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with temporary files in ASP.NET?

Note that I'm not talking about the compiler-generated "Temporary ASP.NET Files".

My web application (ASP.NET MVC) uses Graphviz to generate images that are then fed to the client. This requires the creation of temporary files.

What's the best way to deal with these? Is there a way to delete them immediately after they're sent? Should I use a background thread? Something in Application_Start or Application_End?

like image 841
Roger Lipscombe Avatar asked Apr 30 '09 09:04

Roger Lipscombe


2 Answers

couldn't you do it through a controller or use an ASHX (http://www.marklio.com/marklio/CommentView,guid,df8d6471-83fd-4f66-a799-ef8274979f0e.aspx) to stream out the content and delete the temp files once you had finished writing out the stream?

like image 85
jamie Avatar answered Sep 20 '22 23:09

jamie


Graphviz creates the client, and adds them as a link in the page. so you cannot delete them directly.

there are several ways:

  • on application start, noone should use one of these images. so you can delete it
  • you add a reference to the image (e.g. the path) to the cache, and add a CacheItemRemovedCallback, that will delete your image. (limits nicely the amount of images on your HD
  • make a timer, that deletes the items periodically

be aware, that you should not delete the images, that are created just a second ago. due to they can be used.

like image 45
cRichter Avatar answered Sep 20 '22 23:09

cRichter