Overwiew

Sometimes you need to expand existing archive with one or more file. Obvious way is to extract the archive, put additional files among extracted and compress them together. However it is not optimal since we waste computational resources on files already packed. Aspose.ZIP allows adding entry to ZIP archive without repack. All you need to do is open archive for extraction and add entry to it. This feature works for ZIP, TAR and CPIO archives.

Example How to add new files to existing ZIP archive via C#

This code-snippet demonstrates how to add new files to an existing ZIP archive using C#. The process involves you need to do is open archive for extraction and saving the updated archive.

    using (Archive archive = new Archive("existing.zip"))
    {
        archive.CreateEntry("one_more.bin", "data.bin");
        archive.Save("added.zip");
    }

How to Zip a Folder with .NET

ZIP archives are a versatile tool for managing files: they can compress and combine one or more files or folders into a single package. In .NET , the ZipFile class allows you to easily work with ZIP files for both compression and extraction. The primary benefit of using ZIP archives is to reduce file size. This makes them ideal for storage and transmission, saving valuable space and bandwidth. Additionally, ZIP archives can be encrypted for enhanced security, protecting your sensitive data.

Example How to add new files to existing TAR archive via C#

Want to add new files to your existing TAR archives? This code-snippet will show you exactly how! This code snippet empowers you to seamlessly add new files to your existing TAR archives. No need to recreate the entire archive – simply follow these steps and integrate this code into your workflow for efficient file management.

using (TarArchive archive = new TarArchive("existing.tar"))
{
    archive.CreateEntry("one_more.bin", "data.bin");
    archive.Save("added.tar");
}

Example How to add new files to existing CPIO archive via C#

Looking to incorporate new files into your existing CPIO archives? This code snippet simplifies adding new files to existing CPIO archives. Seamlessly expand your CPIO archives with additional files using this empowering code snippet. Say goodbye to recreating the entire archive – with just a few steps, you can effortlessly integrate this code into your workflow for efficient file management within CPIO archives. Integrate it into your workflow for efficient file management with just a few steps.

    using (CpioArchive archive = new CpioArchive("existing.cpio"))
    {
        archive.CreateEntry("one_more.bin", "data.bin");
        archive.Save("added.cpio");
    }

Conclusion

This page unveiled three powerful C# code snippets for seamlessly adding entries to ZIP, TAR, and CPIO archives. By equipping yourself with these advanced techniques, you’ve unlocked the ability to master advanced file manipulation within existing archives. Unleash your creativity, explore innovative approaches, and leverage C# as a potent tool to elevate your archive management capabilities. Happy coding!
  

Support and Learning Resources

  
  

Aspose.Zip offers individual archive processing APIs for other popular development environments, listed below: