I got a problem with decompression of ZIP files. So firstly, i created 7z file by myself, using system tools. I tried to unpack it manually by 7zip system tools, and it succeed. But when i try to do it from code:
string zipPath = @"c:\Test.7z";
string extractPath = @"c:\extractHere";
ZipFile.ExtractToDirectory(zipPath, extractPath);
I get an exception: An unhandled exception of type 'System.IO.InvalidDataException' occurred in System.IO.Compression.FileSystem.dll.
End of Central Directory record could not be found
I tried reading forum, and everywhere people says the file is corrupt. Im sure it isnt. I also tried this code:
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
}
}
}
This code returning the same error on the very first lane (ZipFile.OpenRead(zipPath). I have a reference to both assemblies in the project:
- System.IO.Compression
- System.IO.Compression.FileSystem
Any ideas what can be wrong ?