disclaimer This question isn't about the appliction of Dispose(). It's not about files being inaccessible. I'm about closing the archive in the proper way without relying on disposing the object.
The following works.
ZipFile.ExtractToDirectory(file, path, true);
File.Delete(file);
This fails with exception: The process cannot access the file 'c:\temp...\file.zip' because it is being used by another process.
ZipFile.ExtractToDirectory(file, path, true);
ZipArchive archive = ZipFile.OpenRead(file);
File.Delete(file);
I've resolved it by disposing the object.
ZipFile.ExtractToDirectory(file, path, true);
ZipArchive archive = ZipFile.OpenRead(file);
archive.Dispose();
File.Delete(file);
I am worried that disposing the object is not the correct approach. Somehow I feel there should be a way to close the file before deletion. There is no such method, however. I googled it but the results I got were about memory streams, general access being denied, manual setting of the attributes.