Search code examples
c#asp.net.net.net-4.5

The name 'ZipFile' does not exist in the current context when including System.IO.Compression


I"m currently running .net version 4.5 and am trying to use it's "new" zip functions. I'm including System.IO.Compression and am trying to run the following code:

using System.IO.Compression;
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";

ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);

The issue I'm getting is that The name 'ZipFile does not exist in the current context. I don't know why it wouldn't exist if I'm already using what requires it.


Solution

  • Have you tried adding the namespace to your current file? To do this add this to the top of the file.

     using System.IO.Compression;