I am using the Ionic.Zip.dll from the DotNetZip library and I'm trying to delete the ZIP file after it finishes unzipping, but I can't manage to do it.
Here is the code I have currently:
using (ZipFile zip = ZipFile.Read(nextVersion + ".zip"))
{
zip.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);
try
{
File.Delete(nextVersion + ".zip");
}
catch (Exception)
{
MessageBox.Show("Could not delete ZIP!");
Environment.Exit(1);
}
}
What am I doing wrong here?
You are getting the exception because the file is still open when you try to delete. Move the File.Delete
to after the using
block.