SaveSelfExtractor Method (exeToGenerate, flavor)

DotNetZip

Ionic Zip Library v1.9.1.6 SaveSelfExtractor Method (exeToGenerate, flavor)
ReferenceIonic.ZipZipFileSaveSelfExtractor(String, SelfExtractorFlavor)
Saves the ZipFile instance to a self-extracting zip archive.
Declaration Syntax
C# Visual Basic Visual C++
public void SaveSelfExtractor(
	string exeToGenerate,
	SelfExtractorFlavor flavor
)
Public Sub SaveSelfExtractor ( _
	exeToGenerate As String, _
	flavor As SelfExtractorFlavor _
)
public:
void SaveSelfExtractor(
	String^ exeToGenerate, 
	SelfExtractorFlavor flavor
)
Parameters
exeToGenerate (String)
a pathname, possibly fully qualified, to be created. Typically it will end in an .exe extension.
flavor (SelfExtractorFlavor)
Indicates whether a Winforms or Console self-extractor is desired.
Remarks

The generated exe image will execute on any machine that has the .NET Framework 2.0 installed on it. The generated exe image is also a valid ZIP file, readable with DotNetZip or another Zip library or tool such as WinZip.

There are two "flavors" of self-extracting archive. The WinFormsApplication version will pop up a GUI and allow the user to select a target directory into which to extract. There's also a checkbox allowing the user to specify to overwrite existing files, and another checkbox to allow the user to request that Explorer be opened to see the extracted files after extraction. The other flavor is ConsoleApplication. A self-extractor generated with that flavor setting will run from the command line. It accepts command-line options to set the overwrite behavior, and to specify the target extraction directory.

There are a few temporary files created during the saving to a self-extracting zip. These files are created in the directory pointed to by TempFileFolder, which defaults to GetTempPath()()()(). These temporary files are removed upon successful completion of this method.

When a user runs the WinForms SFX, the user's personal directory (Environment.SpecialFolder.Personal) will be used as the default extract location. If you want to set the default extract location, you should use the other overload of SaveSelfExtractor()/ The user who runs the SFX will have the opportunity to change the extract directory before extracting. When the user runs the Command-Line SFX, the user must explicitly specify the directory to which to extract. The .NET Framework 2.0 is required on the computer when the self-extracting archive is run.

NB: This method is not available in the version of DotNetZip build for the .NET Compact Framework, nor in the "Reduced" DotNetZip library.

Examples
CopyC#
string DirectoryPath = "c:\\Documents\\Project7";
using (ZipFile zip = new ZipFile())
{
    zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath));
    zip.Comment = "This will be embedded into a self-extracting console-based exe";
    zip.SaveSelfExtractor("archive.exe", SelfExtractorFlavor.ConsoleApplication);
}
CopyVB.NET
Dim DirectoryPath As String = "c:\Documents\Project7"
Using zip As New ZipFile()
    zip.AddDirectory(DirectoryPath, System.IO.Path.GetFileName(DirectoryPath))
    zip.Comment = "This will be embedded into a self-extracting console-based exe"
    zip.SaveSelfExtractor("archive.exe", SelfExtractorFlavor.ConsoleApplication)
End Using

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)