I am using ZipFile class.
A reference/dll must be added in order to use this class. It seems that you can use both the System.IO.Compression
and the Ionic.Zip
dll (one at a time ofcourse).
In my case, only the latter works. The problem though, is that the Ionic.Zip
doesn't seem to have the method: ExtracToFile(...)
which overwrites an existing file. I need this method badly.
Instead, I can only do:
zip.Extract(extractDirectory);
(Then I get an error saying the file already exist)
If I do:
zip.ExtractToFile(extractDirectory);
I get an error saying that the method ExtractToFile does not exist.
Another thing to note, is that doing Using System.IO.Compression
, I get an error when I do:
var zip = ZipFile.Read(finalFileToUnzip)
which says that it can't find ZipFile (although I did add the dll as a reference, doing "Add Reference -> and selecting the .dll file")
If I do Using Ionic.Zip
, it will accept: var zip = ZipFile.Read(finalFileToUnzip)
I am not able to find any info or previous posts about this issue, I hope anyone can help
Any idea about what might be the problem?
Here is more code:
for (int i = 0; i < listWithZipToUnpack.Count; ++i)
{
extractDirectory = Path.Combine(projectPath.ToString(), pathDir + listWithZipToUnpack[i]);
var finalFileToUnzip = Path.Combine(projectPath.ToString(), pathDir, "Lely", listWithZipToUnpack[i]);
if (finalFileToUnzip.Equals("--Vælg fil--")) { continue; }
using (var zip = ZipFile.OpenRead(finalFileToUnzip))
{
if (!Directory.Exists(extractDirectory))
{
Directory.CreateDirectory(extractDirectory+"-"+listWithZipToUnpack[i]);
}
foreach (var zipArchiveEntry in zip.Entries)
{
zipArchiveEntry.ExtractToFile(extractDirectory);
}
}
}
I am using .NET framework 4.5.2
I solved it. The problem is that it is not enough to only add System.IO.Compression
to references, you must also add System.IO.Compression.Filesystem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With