How to Create Self Extracting ZIP using C#

This quick tutorial describes how to create self extracting Zip using C# in the form of an EXE file that can be directly executed to extract the contents on a system having .NET Framework 2.0 or above. It provides the development environment configuration details, a list of necessary namespaces and classes required to accomplish the task, and a runnable sample code in C#. While you create a self extracting ZIP file using C#, it can be customized in a number of ways that are described in this article.

Steps to Create Self Extracting ZIP using C#

  1. Configure the application environment to add Aspose.ZIP for creating SFX ZIP
  2. Create a file stream for the new SFX file
  3. Instantiate an Archive class object
  4. Create an entry in the new archive by providing the entry name and the target file using CreateEntry method
  5. Instantiate SelfExtractorOptions class object to customize output EXE
  6. Save the archive as an EXE file using the custom configuration

These steps describe the process to generate a self extracting ZIP using C# with the help of a sequence of steps required to perform the task. We need to create a file stream that will be used to save the archive file and then create an archive by adding a single file entry into it. Options are also explored to configure the output SFX file before saving it as an EXE file.

Code to Create Self Extracting ZIP using C#

This code demonstrates how to produce a self extracting ZIP using C# by guiding to add a single entry into the archive. Note that you can add a complete folder also into the archive by using the CreateEntries() method that allows selecting a folder to archive. During the process, you can remove some files also from the archive using the DeleteEntry method if required.

This short tutorial has taught us to create an SFX ZIP file however if you want to create a 7z archive, refer to the article on how to create 7z archive in C#.

 English