I have a FileUploader class that can optionally be given a zip file which it extracts to a temporary location and returns the file paths.
From what I understood, implementing the IDisposable interface on the FileUploader class and using the Dispose method to remove all temp files would make the class clean itself up as soon as its reference fell out of context?
This doesnt seem to be the case though – can anyone explain how I might go about what Im trying to achieve?
UPDATE
To clarify, my code is:
public ActionResult ImportFile()
{
FileUploader uploader = new FileUploader(ControllerContext, "file"); // where "file" is the posted form's file element
uploader.SaveOrExtractFilesToTempLocation();
foreach (string file in uploader.files)
{
try
{
// do some stuff
}
catch (Exception err)
{
// let the user know
}
}
return View();
}
Im trying to get the FileUploader to delete all temp files after the ImportFile() method has completed
You’ll need to implement IDisposable correctly. Like the class below.
Then use the class inside a using-block in your main-method like this: