Stats

17 Contributors: 1 Friday, May 12, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap
Download eBook

Reading and writing Zip files

Download .net eBook

Introduction

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

Remarks

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

  • Exceptions

ExceptionCondition
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