Skip to content

Clarify IO package and library reqs #17571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/standard/io/how-to-compress-and-extract-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ The <xref:System.IO.Compression> namespace contains the following types for comp
- <xref:System.IO.Compression.DeflateStream>
- <xref:System.IO.Compression.GZipStream>

The following examples show some of the operations you can perform with compressed files.
The following examples show some of the operations you can perform with compressed files. These examples require the following NuGet packages to be added to your project:

- [System.IO.Compression](https://www.nuget.org/packages/System.IO.Compression)
- [System.IO.Compression.ZipFile](https://www.nuget.org/packages/System.IO.Compression.ZipFile)

If you're using .NET Framework, add references to these two libraries to your project:

- `System.IO.Compression`
- `System.IO.Compression.FileSystem`

## Example 1: Create and extract a .zip file

The following example shows how to create and extract a compressed *.zip* file by using the <xref:System.IO.Compression.ZipFile> class. The example compresses the contents of a folder into a new *.zip* file, and then extracts the zip to a new folder.

To run the sample, create a *start* folder in your program folder and populate it with files to zip.

If you get the build error "The name 'ZipFile' does not exist in the current context," add a reference to the `System.IO.Compression.FileSystem` assembly to your project.

[!code-csharp[System.IO.Compression.ZipFile#1](../../../samples/snippets/csharp/VS_Snippets_CLR_System/system.io.compression.zipfile/cs/program1.cs#1)]
[!code-vb[System.IO.Compression.ZipFile#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR_System/system.io.compression.zipfile/vb/program1.vb#1)]

Expand All @@ -40,10 +46,6 @@ The next example iterates through the contents of an existing *.zip* file and ex

To run the sample, place a *.zip* file called *result.zip* in your program folder. When prompted, provide a folder name to extract to.

If you get the build error "The name 'ZipFile' does not exist in the current context," add a reference to the `System.IO.Compression.FileSystem` assembly to your project.

If you get the error "The type 'ZipArchive' is defined in an assembly that is not referenced," add a reference to the `System.IO.Compression` assembly to your project.

> [!IMPORTANT]
> When unzipping files, you must look for malicious file paths, which can escape out of the directory you unzip into. This is known as a path traversal attack. The following example demonstrates how to check for malicious file paths and provides a safe way to unzip.

Expand Down