-->
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:
- Launch WinZIP from the Start menu or Desktop. Click on File-Open archive in the WinZIP main menu. In the file open dialog select ZIP file you want to open and click 'Open'. You will see contents of the ZIP file and every file and folder stored in it. Select files and folders you want to extract and click on the 'Extract to' icon.
- The folder will be compressed into a ZIP file. The new ZIP file will be located in the same location as the folder that you compressed. You can also select multiple files in your file explorer, right-click on one of them, and then follow the above steps. The resulting ZIP file will contain all of the selected files and will be named “Archive.
This Linux command creates a copy of the myfile.txt file and renames the new file to myfile2.txt. By default, the cp command runs in the same directory you are working in. However, the same file cannot exist twice in the same directory. You’ll need to change the name of the target file to copy in the same location.
How to master a song on logic pro x. 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.
How To Zip A File Folder Right Click
How To Send Zip Folder
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.
How To Zip A File Folder In Windows 10
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 file by using many common tools. The following example shows how to compress and decompress a directory of files by using the GZipStream class: