Unable to delete Package File after an exception during opening
Posted on 2011-10-17
I am creating a package file and fill content in it. For some reason, the package will get corrupt.
I wanted to handle this in this way:
using (Package archivePkg = Package.Open("TestLogFile.zip", FileMode.OpenOrCreate))
} //end of using
} //end of try
catch (IndexOutOfRangeException ex)
File.Delete("TestLogFile.zip"); // IOException
//also at this point I am not able to delete the file
The exception of a corrupt zip file is caught but I am not able to delete the file: It is occupied by another process (my program!). I tested a lot of variants with using / try/catch but without success!