I have the following code block in my application:
try
{
string extractPath = @"C:\Documents";
using (ZipArchive zip = ZipFile.Open(zipFP, ZipArchiveMode.Read))
foreach(ZipArchiveEntry entry in zip.Entries)
{
try
{
extractedPDF = System.IO.Path.Combine(extractPath, entry.FullName);
entry.ExtractToFile(extractedPDF, true);
}
catch (System.IO.IOException)
{
Console.WriteLine("File already exists... ");
Console.WriteLine("Error during extraction... ");
}
}
Console.WriteLine("PDF extracted from ZIP: '{0}'...", string.Concat(extractPath, zipFP));
PdfPanel.OpenFile(extractedPDF);
}catch(AccessViolationException ex)
{
Console.WriteLine("Can't display a zip in the PDF panel... " + ex.InnerException);
}
At the moment, I am getting a compile error on the using
& foreach
lines which highlights ZipArchive
, ZipFile
, ZipArchiveMode
& ZipArchiveEntry
.
The compile error says:
The type or namespace name 'ZipArchive' could not be found (are you missing a using directive or an assembly reference?
But I have a using
statement for System.IO.Compression
at the top of this file, and I am sure that I have added all of the references and other using statements that I need for the code... I copied this code over from a separate project that is fully functioning, and have checked that I have added all of the missing using
statements and references from that project.
What else could be causing this problem? Why isn't the compiler picking up the fact that I am using
the System.IO.Compression
package?
You need to add a reference to the assembly. In the Solution Explorer, under your project right-click References -> Add Reference. Find System.IO.Compression in the list of Framework Assemblies. Check the box for it and press OK.