My website creates a bunch of png files while converting documents from pdf. I have all those files uniquely identified and I want them to be removed at session end. My idea was to create a List, store it in Session and delete each file by path stored in my List<>.
In Global.asax I added:
void Session_End(object sender, EventArgs e)
{
if (Session["cleanUpCollection"] != null)
{
List<String> deletePaths = ((List<string>)(Session["cleanUpCollection"]));
foreach(String s in deletePaths)
{
try
{
System.IO.File.Delete(s);
}
catch { }
}
}
}
In web.config I added this:
<sessionState mode="InProc" cookieless="false" timeout="20" />
but files still sit in temporary location. I have yet to test where this fails but is there a better, common practice of deleting temporary files at session end? BTW, I verified and cleanUpCollection stores local server's paths so there is no error in file path.