Fortunately, the ability to open and decompress RAR files is 'open source' and there are many programs that can do this, including ZIP Extractor. ZIP Extractor has full support for opening the latest version of the RAR file format (Version 5) as well as older versions (Version 3 and Version 4).
- The following example shows how to create and extract a compressed.zip file by using the 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.
- Right click on the compressed file. Choose either open or explore (only one or the other should appear, but explore is preferable).
The System.IO.Compression namespace contains the following types for compressing and decompressing files and streams. You can also use these types to read and modify the contents of a compressed file.
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:
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 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.
Example 2: Extract specific file extensions
The next example iterates through the contents of an existing .zip file and extracts files that have a .txt extension. It uses the ZipArchive class to access the zip, and the ZipArchiveEntry class to inspect the individual entries. The extension method ExtractToFile for the ZipArchiveEntry object is available in the System.IO.Compression.ZipFileExtensions class.
To run the sample, place a .zip file called result.zip in your program folder. When prompted, provide a folder name to extract to.
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.
Example 3: Add a file to an existing zip
The following example uses the ZipArchive class to access an existing .zip file, and adds a file to it. The new file gets compressed when you add it to the existing zip.
Example 4: Compress and decompress .gz files
You can also use the GZipStream and DeflateStream classes to compress and decompress data. They use the same compression algorithm. You can decompress GZipStream objects that are written to a .gz How to reinstall os yosemite. file by using many common tools. The following example shows how to compress and decompress a directory of files by using the GZipStream class:
Fortunately, the ability to open and decompress RAR files is 'open source' and there are many programs that can do this, including ZIP Extractor. ZIP Extractor has full support for opening the latest version of the RAR file format (Version 5) as well as older versions (Version 3 and Version 4).
- The following example shows how to create and extract a compressed.zip file by using the 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.
- Right click on the compressed file. Choose either open or explore (only one or the other should appear, but explore is preferable).
The System.IO.Compression namespace contains the following types for compressing and decompressing files and streams. You can also use these types to read and modify the contents of a compressed file.
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:
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 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.
Example 2: Extract specific file extensions
The next example iterates through the contents of an existing .zip file and extracts files that have a .txt extension. It uses the ZipArchive class to access the zip, and the ZipArchiveEntry class to inspect the individual entries. The extension method ExtractToFile for the ZipArchiveEntry object is available in the System.IO.Compression.ZipFileExtensions class.
To run the sample, place a .zip file called result.zip in your program folder. When prompted, provide a folder name to extract to.
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.
Example 3: Add a file to an existing zip
The following example uses the ZipArchive class to access an existing .zip file, and adds a file to it. The new file gets compressed when you add it to the existing zip.
Example 4: Compress and decompress .gz files
You can also use the GZipStream and DeflateStream classes to compress and decompress data. They use the same compression algorithm. You can decompress GZipStream objects that are written to a .gz How to reinstall os yosemite. file by using many common tools. The following example shows how to compress and decompress a directory of files by using the GZipStream class: