Add Files to TAR

Many people find it frustrating to add new files to existing TAR archives. The typical process involves extracting the whole archive, inserting the latest files, and then recompressing everything into a new TAR archive. Not only is this approach laborious, but it can also be very time-consuming, especially for those who deal with multiple TAR files.

IronZIP offers a more efficient solution that can save both time and energy. IronZIP features an intuitive Add method, this functionality enables users to seamlessly incorporate new files into existing TAR archives without requiring extraction. In the following example, we’ll showcase the straightforward nature of the Add method, illustrating how it simplifies adding files with just a few lines of code. Say farewell to cumbersome methods and adopt a more efficient way to manage your TAR archives!

Add Files to TAR with C#

  1. using IronZip
  2. using (var archive = IronTarArchive.FromFile("existing.tar"))
  3. archive.Add("./assets/image3.png");
  4. archive.Add("./assets/image4.png");
  5. archive.SaveAs("result.tar");

Accessing Existing TAR to Add Files

We first import the namespace IronZip. Afterward, we initialize a new IronTarArchive, then use the FromFile method to import the existing TAR.

Adding Files

Once you've accessed the TAR file, you can add new files using the Add method. This method requires a single parameter—the file path of the item you want to include. If the path is incorrect, the operation will not succeed. In the example provided, we are adding two image files, image3.png and image4.png, to the existing TAR using the Add method.

In addition to PNG files, IronZIP is compatible with various other formats. Users can include popular image types like JPG and SVG and multi-frame formats such as TIFF and GIF. For text and audio based files, IronZIP supports PDFs, DOCX, XLSX files, and audio formats like MP3 and WAV. Remarkably, you can add TAR files within another TAR file, allowing for great flexibility. For a comprehensive list of supported file types, please check here.

Exporting the TAR

In conclusion, once the files are incorporated into the current TAR archive, we invoke the SaveAs function to specify a new name for the updated TAR archive that now includes the additional files.

Discover How to Create, Read, and Extract ZIP Files with IronZIP!

Ready to Get Started?
Nuget Downloads 14,507 | Version: 2025.9 just released