### Execute Basic Archiving Operations (Alternative)
Source: https://github.com/iron-software/ironzip.examples/blob/main/README.md
An alternative example showing extraction and creation of a ZIP archive with files. Comments provide additional context on file paths and operations.
```csharp
using IronZip;
string zipPath = "./archive.zip";
IronZipArchive.ExtractArchiveToDirectory(zipPath, "unarchived"); // Extracts files into the 'unarchived' directory
// Initiating a new ZIP archive
using (var archive = new IronZipArchive())
{
// Insert files into the archive
archive.Add("./assets/doc.pdf"); // Adding a PDF document
archive.Add("./assets/img.png"); // Adding an image file
// Save the constructed ZIP archive
archive.SaveAs("./output/archive.zip"); // The archive is stored at specified path
}
```
--------------------------------
### Install IronZIP Package
Source: https://github.com/iron-software/ironzip.examples/blob/main/quickstart/README.md
Install the IronZIP NuGet package using the Package Manager Console.
```shell
Install-Package IronZip
```
--------------------------------
### Create a TAR File with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/create-tar/README.md
This snippet demonstrates the basic steps to create a TAR file using IronZip. It includes adding image and PDF files to the archive before saving it.
```csharp
using IronZip;
using (var archive = new IronTarArchive())
{
archive.Add("./assets/image1.jpg");
archive.Add("./assets/example.pdf");
archive.SaveAs("output.tar");
}
```
--------------------------------
### Create a New Zip Archive
Source: https://github.com/iron-software/ironzip.examples/blob/main/tutorials/create-read-extract-zip/README.md
Initialize an empty ZIP archive and add files from specified paths. Save the archive to a file.
```csharp
using IronZip;
// Initialize an empty ZIP
using (var archive = new IronZipArchive())
{
// Include files in the ZIP
archive.Add("./assets/image1.png");
archive.Add("./assets/image2.png");
// Complete the ZIP file creation
archive.SaveAs("output.zip");
}
```
--------------------------------
### Basic ZIP Archive Operations in C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/README.md
Demonstrates how to extract an existing ZIP archive and create a new one, adding files to it before saving. Ensure the 'archive.zip' file exists and the 'output' directory is accessible.
```csharp
using IronZip;
string filePath = "./archive.zip";
IronZipArchive.ExtractArchiveToDirectory(filePath, "unarchived"); // Extracting ZIP contents to folder 'unarchived'
// Initiating a new ZIP archive
using (var archive = new IronZipArchive())
{
// Adding files
archive.Add("./assets/doc.pdf");
archive.Add("./assets/img.png");
// Writing ZIP to disk
archive.SaveAs("./output/archive.zip");
}
```
--------------------------------
### Basic Archiving Operations with IronZIP
Source: https://github.com/iron-software/ironzip.examples/blob/main/README.md
Demonstrates how to extract an existing ZIP archive and create a new one by adding files. The archive is saved to a specified path.
```csharp
using IronZip;
string filePath = "./archive.zip";
IronZipArchive.ExtractArchiveToDirectory(filePath, "unarchived"); // This decompresses files into the 'unarchived' folder
// Creating a new ZIP archive
using (var archive = new IronZipArchive())
{
// Adding files to the archive
archive.Add("./assets/doc.pdf");
archive.Add("./assets/img.png");
// Finalizing and saving the ZIP file
archive.SaveAs("./output/archive.zip");
}
```
--------------------------------
### Create a GZIP File in C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/create-gzip/README.md
This snippet demonstrates how to create a new GZIP archive, add a TAR file to it, and save the result as a .tgz file. Ensure the IronZip library is referenced and the IronZip namespace is included.
```csharp
using IronZip;
// ...
var archive = new IronGZipArchive();
archive.Add("output.tar");
archive.SaveAs("output.tgz");
```
--------------------------------
### Create a ZIP File with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/create-zip/README.md
Use IronZip to create a new ZIP archive, add files from URLs, and save it to a specified path. Ensure the IronZip namespace is imported.
```csharp
using IronZip;
using (var archive = new IronZipArchive()) {
archive.Add("https://ironsoftware.com/assets/image1.jpg");
archive.Add("https://ironsoftware.com/assets/example.pdf");
archive.SaveAs("output.zip");
}
```
--------------------------------
### Create a ZIP Archive
Source: https://github.com/iron-software/ironzip.examples/blob/main/quickstart/README.md
Create a new ZIP file and add entries using the AddArchiveEntry and SaveAs methods within a using block.
```csharp
using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Create a new ZIP file instance
using (var archive = new ZipArchive())
{
// Adding a file to the ZIP
archive.AddArchiveEntry("example.txt", File.ReadAllBytes("path/to/example.txt"));
// Finalize and save the ZIP file
archive.SaveAs("archive.zip");
}
}
}
```
--------------------------------
### Apply License Key via Web.Config or App.Config
Source: https://github.com/iron-software/ironzip.examples/blob/main/get-started/license-keys/README.md
Globally set your IronZIP license for your application by adding the key to the appSettings section of your Web.Config or App.Config file.
```xml
...
...
```
--------------------------------
### Activate IronZIP License
Source: https://github.com/iron-software/ironzip.examples/blob/main/quickstart/README.md
Activate IronZIP by setting your license key after the using directive and before any IronZIP functionalities are invoked.
```csharp
using IronZip;
// Insert your license key below
IronZip.License.LicenseKey = "YOUR_LICENSE_KEY";
```
--------------------------------
### Add Files to TAR with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/add-files-to-tar/README.md
Use this snippet to add new files to an existing TAR archive. Ensure the 'existing.tar' file is present and accessible. The 'Add' method accepts file paths or URLs.
```csharp
using IronZip;
using (var archive = IronTarArchive.FromFile("existing.tar"))
{
archive.Add("https://ironsoftware.com/assets/image3.png");
archive.Add("https://ironsoftware.com/assets/image4.png");
archive.SaveAs("result.tar");
}
```
--------------------------------
### Set License Key in .NET Core appsettings.json
Source: https://github.com/iron-software/ironzip.examples/blob/main/get-started/license-keys/README.md
Apply the IronZIP license key globally in a .NET Core application by adding it to the appsettings.json file. Ensure this file is set to 'Copy always' to the output directory.
```json
{
"IronZip.LicenseKey":"IRONZIP.MYLICENSE.KEY.1EF01"
}
```
--------------------------------
### Preview Archive Entries using C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/view-archive-entries/README.md
Use this snippet to list the names of all entries within a ZIP archive without extracting them. Ensure the IronZip namespace is included and an IronZipArchive instance is created with the path to your ZIP file.
```csharp
using IronZip;
using (var archive = new IronZipArchive("existing.zip"))
{
List entries = archive.Entries();
foreach (Entry entry in entries)
{
Console.WriteLine(entry.Name);
}
}
```
--------------------------------
### Unpacking Protected Zip Files with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/extract-protected-zip/README.md
Use the `IronZipArchive.ExtractToDirectory` method to extract a password-protected ZIP file to a specified output directory. Ensure the correct password is provided as the third argument.
```csharp
using IronZip;
IronZipArchive.ExtractToDirectory("secured.zip", "outputFolder", "SecureP@ss");
```
--------------------------------
### Add Files to an Existing ZIP Archive
Source: https://github.com/iron-software/ironzip.examples/blob/main/quickstart/README.md
Append additional files to an existing ZIP archive by using AddArchiveEntry and then saving the changes.
```csharp
using IronZip;
using System.IO;
class Program
{
static void Main()
{
// Accessing an existing ZIP file
using (var archive = new ZipArchive("archive.zip"))
{
// Append another file
archive.AddArchiveEntry("anotherfile.txt", File.ReadAllBytes("path/to/anotherfile.txt"));
// Commit changes to the same ZIP file
archive.SaveAs("archive.zip");
}
}
}
```
--------------------------------
### Extract GZIP File to Directory in C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/extract-gzip/README.md
Use IronGZIPArchive.ExtractArchiveToDirectory to decompress a GZIP file into a specified output directory. Ensure the IronZip library is referenced.
```csharp
using IronZip;
// ...
IronGZipArchive.ExtractArchiveToDirectory("output.tgz", "extracted");
```
--------------------------------
### Unzip Archive to a Directory
Source: https://github.com/iron-software/ironzip.examples/blob/main/quickstart/README.md
Extract files from a ZIP archive to a specified directory using the ExtractArchiveToDirectory method.
```csharp
using IronZip;
class Program
{
static void Main()
{
// Define the ZIP and extraction paths
string zipPath = "archive.zip";
string extractPath = "extracted/";
// Perform extraction
using (var archive = new ZipArchive(zipPath))
{
archive.ExtractArchiveToDirectory(extractPath);
}
}
}
```
--------------------------------
### Add Files to ZIP with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/add-files-to-zip/README.md
Use this snippet to add new files directly to an existing ZIP archive. Ensure the IronZip namespace is imported and provide correct paths for the existing ZIP file and the files to be added.
```csharp
using IronZip;
using (var archive = IronZipArchive.FromFile("existing.zip")) {
archive.Add("./assets/image3.png");
archive.Add("./assets/image4.png");
archive.SaveAs("result.zip");
}
```
--------------------------------
### Extract BZIP2 File with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/extract-bzip2/README.md
Use the IronBZip2Archive.ExtractArchiveToDirectory method to decompress a BZIP2 file to a specified directory. Ensure the input file path includes the .bz2 extension.
```csharp
using IronZip;
IronBZip2Archive.ExtractArchiveToDirectory("output.txt.bz2", "extracted");
```
--------------------------------
### Extract TAR File with C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/extract-tar/README.md
Use the IronTarArchive.ExtractArchiveToDirectory method to extract a TAR file to a specified output directory. Ensure the IronZip namespace is included.
```csharp
using IronZip;
IronTarArchive.ExtractArchiveToDirectory("output.tar", "extracted");
```
--------------------------------
### Decrypt and Encrypt ZIP Files with IronZIP
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/access-protected-zip/README.md
Use this snippet to decrypt an existing ZIP file with a password and then re-encrypt it using AES256 encryption. Ensure the IronZip and IronZip.Enum namespaces are included.
```csharp
using IronZip;
using IronZip.Enum;
using (var archive = new IronZipArchive("protected.zip", "NewP@ss"))
archive.Encrypt("NewP@ss", EncryptionMethods.AES256);
```
--------------------------------
### Extracting a ZIP File Using C#
Source: https://github.com/iron-software/ironzip.examples/blob/main/examples/extract-zip/README.md
Use this snippet to extract the contents of a ZIP file to a specified directory. Ensure the IronZip namespace is included and provide the absolute path to the ZIP file.
```csharp
using IronZip;
IronZipArchive.ExtractArchiveToDirectory("output.zip", "extracted");
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.