.NET FrameworkReading and writing Zip files

Download .NET Framework for free


The ZipFile class lives in the System.IO.Compression namespace. It can be used to read from, and write to Zip files.


  • You can also use a MemoryStream instead of a FileStream.

  • Exceptions

ArgumentExceptionThe stream has already been closed, or the capabilities of the stream does not match the mode (eg: trying to write to a read only stream)
ArgumentNullExceptioninput stream is null
ArgumentOutOfRangeExceptionmode has an invalid value
InvalidDataExceptionSee list below

When a InvalidDataException is thrown, it can have 3 causes:

  • The contents of the stream could not be interpreted as a zip archive
  • mode is Update and an entry is missing from the archive or is corrupt and cannot be read
  • mode is Update and an entry is too large to fit into memory

All information has been taken from this MSDN page

Related Examples

Extracting files from ZIP files