views:

94

answers:

2

Hi, I have some problems to delete temporary folder and files on my server when users not finish some action in webpages and quit to other webpages. Initialy at Page Load folders are created to allow the user to load files.I have tried implementing destruction during Idisposable without success. Could someone point the best method to delete folders and files when user quit the page with no action or cancel button. Thanks.

A: 

I am not sure why you want to create temp folders and files. But deleting them on no action is ugly way to rely on, because you have depend on some timers. You could use System.IO.Path.GetTempPath() to get a temp file and system would take care of deletion.

Actually, Windows will not automatically empty the temp folder.
SLaks
+2  A: 

You can investigate the OnUnload event of the page but, honestly, your best bet is to have a script run periodically and delete all files from the temp folder older than some reasonable amount. e.g. run at midnight and delete all files created more the 24 hours ago (or less, if disk space is a problem).

Zarigani
I have tested but i'm not happy with result. Other way is use one Session End event in Global asax but is not raised if session is stored in StateServer or SQLServer in prod mode. Temporary folders are not well managed if you need to transfert files later in the server.
If you mean you're not happy with using the OnUnload event then, yes, that's why I recommended running a script. When I said "temp folder" I meant your temp folder, not any kind of OS temp folder. I'm not entirely clear on what you mean by "not well managed"?
Zarigani
Is not working as escompted to transfert contents from temp folders to a webserver. I have returned to create std user temp.folders directly in the server.// Run one script using quartz, i don´t like very much. I would prefer manage directly in place using some controled event.