The following example demonstrates how to extract the contents of a zip file which is located in the resources of an application using the StreamFile class. The StreamFile class implements access to any type of stream as though it were a file.
To extract the contents of a zip file located in an application's resources, the following steps must be performed:
Create a stream that accesses a zip file contained within the resources of an application This is done using the .NET Framework's GetManifestResourceStream method.
Initrialize a new instance of the StreamFile class around the stream that accesses the zip file in the resources of the application specifying the name by which to access the zip file.
Retrieve a reference to the zip file in the resources using the ZipArchive class.
Retrieve a reference to a folder where the files will be extracted to using either the DiskFolder, ZippedFolder, ZipArchive, MemoryFolder or IsolatedFolder classes. With Xceed Zip for .NET, a folder is a folder; it does not matter if it is located within a zip file, on disk or in memory.
Copy the files from the zip file to a destination folder using the CopyFilesTo method. With Xceed Zip for .NET, a folder is a folder; it does not matter if it is located within a zip file, on disk or in memory.
The following example demonstrates how to extract files from a zip file located in an application's resources.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
The main questions you should ask yourself when copying items to a zip file are:
Do you want to filter (specify specific files and folders) the items that are to be unzipped? Use filters.
Do you want to display the status of the operation? See the Events topic.
Do you only want to copy a specific file or folder? Use the CopyTo method.
Do you want to move items rather than copy them? Use the MoveTo and MoveFilesTo methods.