<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://code.msdn.microsoft.com/rss.xsl"?><rss version="2.0"><channel><title>Manage ZIP files from within .NET applications</title><link>http://code.msdn.microsoft.com/DotNetZip/Project/ProjectRss.aspx</link><description>Need to create a zip file from within a .NET application&amp;#63;    Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;     Display the con...</description><item><title>UPDATED RELEASE: ASP.NET - handle ZIP files (VB + Csharp) (Jan 03, 2009)</title><link>http://code.msdn.microsoft.com/DotNetZip/Release/ProjectReleases.aspx?ReleaseId=2015</link><description></description><author></author><pubDate>Thu, 10 Sep 2009 20:28:47 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: ASP.NET - handle ZIP files (VB + Csharp) (Jan 03, 2009) 20090910P</guid></item><item><title>RELEASED: UnZip with ProgressBar (VB.NET, WinForms) (Aug 12, 2009)</title><link>http://code.msdn.microsoft.com/DotNetZip/Release/ProjectReleases.aspx?ReleaseId=3097</link><description></description><author></author><pubDate>Wed, 12 Aug 2009 07:04:49 GMT</pubDate><guid isPermaLink="false">RELEASED: UnZip with ProgressBar (VB.NET, WinForms) (Aug 12, 2009) 20090812A</guid></item><item><title>CREATED RELEASE: UnZip with ProgressBar (VB.NET, WinForms) (Aug 12, 2009)</title><link>http://code.msdn.microsoft.com/DotNetZip/Release/ProjectReleases.aspx?ReleaseId=3097</link><description></description><author></author><pubDate>Wed, 12 Aug 2009 07:04:49 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: UnZip with ProgressBar (VB.NET, WinForms) (Aug 12, 2009) 20090812A</guid></item><item><title>UPDATED WIKI: TreeViewZip-VB</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Show a ZIP within a TreeView in WinForms (VB)
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6499" alt="TreeViewZip-VB.png" /&gt;&lt;br /&gt; &lt;br /&gt;This app is a VB WinForms app that displays the contents of a ZIP file in a TreeView. &lt;br /&gt; &lt;br /&gt;Below is the code for the just the Form.  The most interesting methods for building the TreeView are AddTreeNode() and FindNodeForTag().   The approach is to enumerate (For Each) the entries in the zip file, and for each one, add a node to the treeview, and any required node hierarchy according to the path of the ZipEntry.  &lt;br /&gt; &lt;br /&gt;What is not shown is how to use the TreeView thus populated.  One interesting possibility is to allow a right-click context menu popup, and extraction of a particular entry.  This should be easy to achieve.  The Tag property on each node defines the path of the ZipEntry, and this path can be used in the string indexer on the ZipFile instance.  So in the onClick method for the context menu item, you can do zip(node.Tag).Extract(). &lt;br /&gt; &lt;br /&gt;To get a zip of the complete Visual Studio solution for this simple example, see &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2952" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿Imports Ionic.Zip
Imports System.Linq
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        PopulateTreeView()
    End Sub
 
    Private zip As Ionic.Zip.ZipFile
 
    ''' &amp;lt;summary&amp;gt;
    ''' Populates TreeView1 with the entries in the zipfile, named by TextBox1
    ''' &amp;lt;/summary&amp;gt;
    Private Sub PopulateTreeView()
        Try
            zip = ZipFile.Read(Me.TextBox1.Text)
 
            Me.TreeView1.Nodes.Clear()
            For Each e As ZipEntry In zip
                AddTreeNode(e.FileName)
            Next
 
        Catch ex As Exception
            '' eg, file does not exist, or access denied, etc
            MessageBox.Show(&amp;quot;Exception: &amp;quot; + ex.ToString(), _
                            &amp;quot;Exception during zip processing&amp;quot;, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
 
        Finally
            If Not (zip Is Nothing) Then
                zip.Dispose()
            End If
 
        End Try
    End Sub
 
    ''' &amp;lt;summary&amp;gt;
    ''' Add a node to the Treeview, for the given ZipEntry name
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the TreeNode added&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' Entries in a zip file exist in a &amp;quot;flat container space&amp;quot;: there is a single container, 
    ''' the zip file itself, that contains all entries. Even though each entry has a filename 
    ''' attached to it, and that filename may include a hierarchial directory path, the entry is 
    ''' always contained in the zipfile itself.  Even though it is possible to include directory 
    ''' entries in a zip file, those directory entries are not, themselves, containers - they do 
    ''' not contain other zip entries.  
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' This method overlays the zipentry, which exists only in a flat namespace, into a hierarchial 
    ''' tree, creating that tree from the pathname on the entry.  If the entry name is /a/b/c.txt,  
    ''' then this method adds 3 nodes to the TreeView, one for each segment in the path. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' The method is smart enough to find existing nodes matching subsegements of the path
    ''' for an entry. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;/remarks&amp;gt;
    Private Function AddTreeNode(ByVal name As String) As TreeNode
        If (name.EndsWith(&amp;quot;/&amp;quot;)) Then
            name = name.Substring(0, name.Length - 1)
        End If
        Dim node As TreeNode = FindNodeForTag(name, Me.TreeView1.Nodes)
        If Not (node Is Nothing) Then
            Return node
        End If
        Dim pnodeCollection As TreeNodeCollection
        Dim parent As String = Path.GetDirectoryName(name)
        If (parent = &amp;quot;&amp;quot;) Then
            pnodeCollection = Me.TreeView1.Nodes
        Else
            pnodeCollection = AddTreeNode(parent.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)).Nodes
        End If
        node = New TreeNode
        node.Text = Path.GetFileName(name)
        node.Tag = name ' full path
        pnodeCollection.Add(node)
        Return node
    End Function
 
    ''' &amp;lt;summary&amp;gt;
    ''' Returns the TreeNode for a given name 
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name=&amp;quot;nodes&amp;quot;&amp;gt;The TreeNodeCollection to search&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the matching TreeNode, or nothing if none exists&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' This method is used by AddTreeNode() to find existing nodes.  
    ''' &amp;lt;/remarks&amp;gt;
    Private Function FindNodeForTag(ByVal name As String, ByRef nodes As TreeNodeCollection) As TreeNode
        For Each node As TreeNode In nodes
            If (name = node.Tag) Then
                Return node
            ElseIf (name.StartsWith(node.Tag + &amp;quot;/&amp;quot;)) Then
                Return FindNodeForTag(name, node.Nodes)
            End If
        Next
        Return Nothing
    End Function
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog
 
        openFileDialog1.InitialDirectory = Me.TextBox1.Text
        openFileDialog1.Filter = &amp;quot;zip files|*.zip|EXE files|*.exe|All Files|*.*&amp;quot;
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True
 
        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            Me.TextBox1.Text = openFileDialog1.FileName
            If (System.IO.File.Exists(Me.TextBox1.Text)) Then
                Button1_Click(sender, e)
            End If
        End If
 
    End Sub
End Class
 
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 17:16:29 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TreeViewZip-VB 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=20</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
DotNetZip Examples
&lt;/h1&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;Display the contents of a zip file from within a Smart Device app&amp;#63;  Show the contents of a zip file in a WinForms TreeView&amp;#63; Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more.  This set of code pages shows you how.  &lt;br /&gt;&lt;br /&gt;DotNetZip is a FREE open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;
&lt;br /&gt; &lt;br /&gt;Find out more about DotNetZip on &lt;a href="http://DotNetZip.codeplex.com/" class="externalLink"&gt;http://DotNetZip.codeplex.com/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;h2&gt;
Create a ZIP within ASP.NET 
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within WinForms (C#)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within WinForms (VB)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within a Console app (C#)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6506" alt="DotNetZip-Console-1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Show a ZIP within a TreeView in WinForms (VB)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6498" alt="TreeViewZip-VB.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Examples with code
&lt;/h1&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:46:47 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: Console Example</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console Example&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Create a zip within a Console app
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6503" alt="DotNetZip-Console-1.png" /&gt;&lt;br /&gt; &lt;br /&gt;This is a full console-based app that zips up files and directories from the command line.&lt;br /&gt;I include the source here just for your edification and amusement. &lt;br /&gt;You can also &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2017" class="externalLink"&gt;download the Visual Studio project&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
// ZipIt.cs
// 
// ----------------------------------------------------------------------
// Copyright (c) 2006, 2007, 2008 Dino Chiesa and Microsoft Corporation.  
// All rights reserved.
//
// This example is released under the Microsoft Permissive License of
// October 2006.  See the license.txt file accompanying this release for 
// full details. 
//
// ----------------------------------------------------------------------
//
// This utility zips up a set of files and directories specified on the command line.
//
// compile with:
//     csc /debug+ /target:exe /r:Ionic.Utils.Zip.dll /out:ZipIt.exe ZipIt.cs 
//
// Fri, 23 Feb 2007  11:51
//
 
using System;
using Ionic.Zip;
 
namespace Ionic.Zip.Examples
{
 
    public class ZipIt
    {
        private static void Usage()
        {
            string UsageMessage =
            &amp;quot;Zipit.exe:  zip up a directory, file, or a set of them, into a zipfile.\n&amp;quot; +
            &amp;quot;            Depends on Ionic's DotNetZip library. This is version {0} of the utility.\n&amp;quot; +
            &amp;quot;usage:\n   ZipIt.exe &amp;lt;ZipFileToCreate&amp;gt; [arguments]\n&amp;quot; +
            &amp;quot;\narguments: \n&amp;quot; +
            &amp;quot;  -utf8                 - use UTF-8 encoding for entries with comments or\n&amp;quot; +
            &amp;quot;                          filenames that cannot be encoded with the default IBM437\n&amp;quot; +
            &amp;quot;                          code page.\n&amp;quot; +
            &amp;quot;  -64                   - use ZIP64 extensions, for large files or large numbers of files.\n&amp;quot; +
            &amp;quot;  -cp &amp;lt;codepage         - use the specified numeric codepage for entries with comments \n&amp;quot; +
            &amp;quot;                          or filenames that cannot be encoded with the default IBM437\n&amp;quot; +
            &amp;quot;                          code page.\n&amp;quot; +
            &amp;quot;  -p &amp;lt;password&amp;gt;         - apply the specified password for all succeeding files added.\n&amp;quot; +
            &amp;quot;                          use \&amp;quot;\&amp;quot; to reset the password to nil.\n&amp;quot; +
            &amp;quot;  -c &amp;lt;comment&amp;gt;          - use the given comment for the archive or, on \n&amp;quot; +
            &amp;quot;  -d &amp;lt;path&amp;gt;             - use the given directory path in the archive for\n&amp;quot; +
            &amp;quot;                          succeeding items added to the archive.\n&amp;quot; +
            &amp;quot;  -s &amp;lt;entry&amp;gt; 'string'   - insert an entry of the given name into the \n&amp;quot; +
            &amp;quot;                          archive, with the given string as its content.\n&amp;quot; +
            &amp;quot;  -flat                 - store the files in a flat dir structure; do not use the \n&amp;quot; +
            &amp;quot;                          directory paths from the source files.\n&amp;quot; +
            &amp;quot;  &amp;lt;directory&amp;gt; | &amp;lt;file&amp;gt;  - add the directory or file to the archive.&amp;quot;;
 
            Console.WriteLine(UsageMessage,
                      System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            Environment.Exit(1);
        }
 
 
 
        public static void Main(String[] args)
        {
            if (args.Length &amp;lt; 2) Usage();
 
            if (!args[0].EndsWith(&amp;quot;.zip&amp;quot;))
            {
                Console.WriteLine(&amp;quot;The filename must end with .zip!\n&amp;quot;);
                Usage();
            }
            if (System.IO.File.Exists(args[0]))
            {
                System.Console.Error.WriteLine(&amp;quot;That zip file ({0}) already exists.&amp;quot;, args[0]);
            }
 
            // because the comments and filenames on zip entries may be UTF-8
            // System.Console.OutputEncoding = new System.Text.UTF8Encoding();
 
            try
            {
                int codePage = 0;
                ZipEntry e = null;
                string entryComment = null;
                string entryDirectoryPathInArchive = &amp;quot;&amp;quot;;
 
                using (ZipFile zip = new ZipFile(args[0]))
                {
                    zip.StatusMessageTextWriter = System.Console.Out;
                    for (int i = 1; i &amp;lt; args.Length; i++)
                    {
                        switch (args[i])
                        {
                            case &amp;quot;-p&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                zip.Password = (args[i] == &amp;quot;&amp;quot;) ? null : args[i];
                                break;
 
                            case &amp;quot;-flat&amp;quot;:
                                entryDirectoryPathInArchive = &amp;quot;&amp;quot;;
                                break;
 
                            case &amp;quot;-utf8&amp;quot;:
                                zip.UseUnicodeAsNecessary = true;
                                break;
 
                            case &amp;quot;-64&amp;quot;:
                                zip.UseZip64WhenSaving = Zip64Option.Always;
                                break;
 
                            case &amp;quot;-s&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                string entryName = args[i];
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                string content = args[i];
                                e = zip.AddFileFromString(entryName, entryDirectoryPathInArchive, content);
                                if (entryComment != null)
                                {
                                    e.Comment = entryComment;
                                    entryComment = null;
                                }
                                break;
 
                            case &amp;quot;-c&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
				entryComment = args[i];  // for the next entry
                                break;
 
                            case &amp;quot;-zc&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                zip.Comment = args[i];
                                break;
 
                            case &amp;quot;-cp&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                System.Int32.TryParse(args[i], out codePage);
                                if (codePage != 0)
                                    zip.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(codePage);
                                break;
 
                            case &amp;quot;-d&amp;quot;:
                                i++;
                                if (args.Length &amp;lt;= i) Usage();
                                entryDirectoryPathInArchive = args[i];
                                break;
 
 
                            default:
                                // UpdateItem will add Files or Dirs, recurses subdirectories
                                zip.UpdateItem(args[i], entryDirectoryPathInArchive);
 
                                // try to add a comment if we have one
                                if (entryComment != null)
                                {
                                    // can only add a comment if the thing just added was a file. 
                                    if (zip.EntryFileNames.Contains(args[i]))
                                    {
                                        e = zip[args[i]];
                                        e.Comment = entryComment;
                                    }
                                    else
                                        Console.WriteLine(&amp;quot;Warning: zipit.exe: ignoring comment; cannot add a comment to a directory.&amp;quot;);
 
                                    // reset the comment
                                    entryComment = null;
                                }
                                break;
                        }
                    }
                    zip.Save();
                }
            }
            catch (System.Exception ex1)
            {
                System.Console.Error.WriteLine(&amp;quot;Exception: &amp;quot; + ex1);
            }
        }
    }
}
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:41:18 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Console Example 20090707P</guid></item><item><title>UPDATED WIKI: WinForms Example</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms Example&amp;version=8</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Create a ZIP within WinForms (C#)
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6502" alt="DotNetZip-Winforms-1.jpg" /&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;This is C# code for a WinForms app showing how to use DotNetZip.  I provide just the Form1.cs file here, but you can also &lt;a href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2016" class="externalLink"&gt;download the full Visual Studio project&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.  Also, see the &lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=similar%20VB%20WinForms%20Example&amp;amp;referringTitle=WinForms%20Example"&gt;similar VB WinForms Example&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;Points of interest here: &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;the progress bars - there are two of them.  One is for the progress on the overall archive.  It gets updated once for each entry in the archive, as the entry is saved in the archive.  For a small archive (let's say, 100 files) this can happen very quickly.  But if you have a zip archive with 40,000 entries, this progress bar will be very helpful in showing state to the user. The second progress bar depicts the progress for the current Entry.  DotNetZip has progress events that are very fine-grained so that you can get an update on how much of the current entry has been saved (56,000 bytes out of 432,000, for example).  &lt;/li&gt;&lt;li&gt;The application also exercises many of the features of DotNetZip - for example it allows the user to employ Unicode encoding for the filenames.  Or, the user can select whether ZIP64 is used or not.  Or, the user can specify whether to create a self-extracting archive.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using Ionic.Zip;
 
namespace WinFormsExample
{
    public partial class Form1 : Form
    {
        delegate void SaveEntryProgress(SaveProgressEventArgs e);
        delegate void ButtonClick(object sender, EventArgs e);
 
        public Form1()
        {
            InitializeComponent();
 
            InitEncodingsList();
 
            FixTitle();
 
            FillFormFromRegistry();
        }
 
        private void FixTitle()
        {
            this.Text = String.Format(&amp;quot;WinForms Zip Creator Example for DotNetZip v{0}&amp;quot;,
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
        }
 
        private void InitEncodingsList()
        {
            _EncodingNames = new List&amp;lt;string&amp;gt;();
            var e = System.Text.Encoding.GetEncodings();
            foreach (var e1 in e)
            {
                if (!_EncodingNames.Contains(e1.Name))
                    if (!_EncodingNames.Contains(e1.Name.ToUpper()))
                        if (!_EncodingNames.Contains(e1.Name.ToLower()))
                            if (e1.Name != &amp;quot;IBM437&amp;quot; &amp;amp;&amp;amp; e1.Name != &amp;quot;utf-8&amp;quot;)
                                _EncodingNames.Add(e1.Name);
            }
            _EncodingNames.Sort();
            comboBox1.Items.Add(&amp;quot;zip default (IBM437)&amp;quot;);
            comboBox1.Items.Add(&amp;quot;utf-8&amp;quot;);
            foreach (var name in _EncodingNames)
            {
                comboBox1.Items.Add(name);
            }
 
            // select the first item: 
            comboBox1.SelectedIndex = 0;
        }
 
 
 
 
        private void KickoffZipup()
        {
            _folderName = tbDirName.Text;
 
            if (_folderName == null || _folderName == &amp;quot;&amp;quot;) return;
            if (this.tbZipName.Text == null || this.tbZipName.Text == &amp;quot;&amp;quot;) return;
 
            // check for existence of the zip file:
            if (System.IO.File.Exists(this.tbZipName.Text))
            {
                var dlgResult = MessageBox.Show(String.Format(&amp;quot;The file you have specified ({0}) already exists.  Do you want to overwrite this file?&amp;quot;, this.tbZipName.Text), &amp;quot;Confirmation is Required&amp;quot;, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlgResult != DialogResult.Yes) return;
                System.IO.File.Delete(this.tbZipName.Text);
            }
 
            _saveCanceled = false;
            _nFilesCompleted = 0;
            _totalBytesAfterCompress = 0;
            _totalBytesBeforeCompress = 0;
            this.btnOk.Enabled = false;
            this.btnOk.Text = &amp;quot;Zipping...&amp;quot;;
            this.btnCancel.Enabled = true;
            lblStatus.Text = &amp;quot;Zipping...&amp;quot;;
 
            var options = new WorkerOptions
            {
                ZipName = this.tbZipName.Text,
                Folder = _folderName,
                Encoding = &amp;quot;ibm437&amp;quot;
            };
 
            if (this.comboBox1.SelectedIndex != 0)
            {
                options.Encoding = this.comboBox1.SelectedItem.ToString();
            }
 
            if (this.radioFlavorSfxCmd.Checked)
                options.ZipFlavor = 2;
            else if (this.radioFlavorSfxGui.Checked)
                options.ZipFlavor = 1;
            else options.ZipFlavor = 0;
 
            if (this.radioZip64AsNecessary.Checked)
                options.Zip64 = Zip64Option.AsNecessary;
            else if (this.radioZip64Always.Checked)
                options.Zip64 = Zip64Option.Always;
            else options.Zip64 = Zip64Option.Never;
 
            options.Comment = String.Format(&amp;quot;Encoding:{0} || Flavor:{1} || ZIP64:{2}\r\nCreated at {3} || {4}\r\n&amp;quot;,
                        options.Encoding,
                        FlavorToString(options.ZipFlavor),
                        options.Zip64.ToString(),
                        System.DateTime.Now.ToString(&amp;quot;yyyy-MMM-dd HH:mm:ss&amp;quot;),
                        this.Text);
 
            if (this.tbComment.Text != TB_COMMENT_NOTE)
                options.Comment += this.tbComment.Text;
 
 
            _workerThread = new Thread(this.DoSave);
            _workerThread.Name = &amp;quot;Zip Saver thread&amp;quot;;
            _workerThread.Start(options);
            this.Cursor = Cursors.WaitCursor;
 
        }
 
        private string FlavorToString(int p)
        {
            if (p == 2) return &amp;quot;SFX-CMD&amp;quot;;
            if (p == 1) return &amp;quot;SFX-GUI&amp;quot;;
            return &amp;quot;ZIP&amp;quot;;
        }
 
 
        private bool _firstFocusInCommentTextBox = true;
        private void tbComment_Enter(object sender, EventArgs e)
        {
            if (_firstFocusInCommentTextBox)
            {
                tbComment.Text = &amp;quot;&amp;quot;;
                tbComment.Font = new System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                tbComment.ForeColor = System.Drawing.SystemColors.WindowText;
                _firstFocusInCommentTextBox = false;
            }
        }
 
 
        private void tbComment_Leave(object sender, EventArgs e)
        {
            string TextToFind = tbComment.Text;
 
            if ((TextToFind == null) || (TextToFind == &amp;quot;&amp;quot;))
            {
                this.tbComment.Font = new System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.tbComment.ForeColor = System.Drawing.SystemColors.InactiveCaption;
                _firstFocusInCommentTextBox = true;
                this.tbComment.Text = TB_COMMENT_NOTE;
            }
        }
 
 
        private void SetProgressBars()
        {
            if (this.progressBar1.InvokeRequired)
            {
                this.progressBar1.Invoke(new MethodInvoker(this.SetProgressBars));
            }
            else
            {
                this.progressBar1.Value = 0;
                this.progressBar1.Maximum = _entriesToZip;
                this.progressBar1.Minimum = 0;
                this.progressBar1.Step = 1;
                this.progressBar2.Value = 0;
                this.progressBar2.Minimum = 0;
                this.progressBar2.Maximum = 1; // will be set later, for each entry.
                this.progressBar2.Step = 1;
            }
        }
 
 
        private void DoSave(Object p)
        {
            WorkerOptions options = p as WorkerOptions;
            try
            {
                using (var zip1 = new ZipFile())
                {
                    zip1.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(options.Encoding);
                    zip1.Comment = options.Comment;
                    zip1.AddDirectory(options.Folder);
                    _entriesToZip = zip1.EntryFileNames.Count;
                    SetProgressBars();
                    zip1.SaveProgress += this.zip1_SaveProgress;
 
                    zip1.UseZip64WhenSaving = options.Zip64;
 
                    if (options.ZipFlavor == 1)
                        zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.WinFormsApplication);
                    else if (options.ZipFlavor == 2)
                        zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.ConsoleApplication);
                    else
                        zip1.Save(options.ZipName);
                }
            }
            catch (System.Exception exc1)
            {
                MessageBox.Show(String.Format(&amp;quot;Exception while zipping: {0}&amp;quot;, exc1.Message));
                btnCancel_Click(null, null);
            }
        }
 
 
 
        void zip1_SaveProgress(object sender, SaveProgressEventArgs e)
        {
            switch (e.EventType)
            {
                case ZipProgressEventType.Saving_AfterWriteEntry:
                    StepArchiveProgress(e);
                    break;
                case ZipProgressEventType.Saving_EntryBytesRead:
                    StepEntryProgress(e);
                    break;
                case ZipProgressEventType.Saving_Completed:
                    SaveCompleted();
                    break;
                case ZipProgressEventType.Saving_AfterSaveTempArchive:
                    TempArchiveSaved();
                    break;
            }
            if (_saveCanceled)
                e.Cancel = true;
        }
 
        private void TempArchiveSaved()
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new MethodInvoker(this.TempArchiveSaved));
            }
            else
            {
                lblStatus.Text = (this.radioFlavorSfxCmd.Checked || this.radioFlavorSfxGui.Checked)
                    ? &amp;quot;Temp archive saved...compiling SFX...&amp;quot;
                    : &amp;quot;Temp archive saved...&amp;quot;;
            }
        }
 
 
 
        private void SaveCompleted()
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new MethodInvoker(this.SaveCompleted));
            }
            else
            {
                lblStatus.Text = String.Format(&amp;quot;Done, Compressed {0} files, {1:N0}% of original.&amp;quot;,
                    _nFilesCompleted, (100.00 * _totalBytesAfterCompress) / _totalBytesBeforeCompress);
 
                ResetState();
            }
        }
 
 
 
        private void StepArchiveProgress(SaveProgressEventArgs e)
        {
            if (this.progressBar1.InvokeRequired)
            {
                this.progressBar1.Invoke(new SaveEntryProgress(this.StepArchiveProgress), new object[] { e });
            }
            else
            {
                if (!_saveCanceled)
                {
                    _nFilesCompleted++;
                    this.progressBar1.PerformStep();
                    _totalBytesAfterCompress += e.CurrentEntry.CompressedSize;
                    _totalBytesBeforeCompress += e.CurrentEntry.UncompressedSize;
 
                    // reset the progress bar for the entry:
                    this.progressBar2.Value = this.progressBar2.Maximum = 1;
 
                    this.Update();
 
                    // Sleep here just to show the progress bar, when the number of files is small,
                    // or when all done. 
                    // You may not want this for actual use!
                    if (this.progressBar2.Value == this.progressBar2.Maximum)
                        Thread.Sleep(350);
                    else if (_entriesToZip &amp;lt; 10)
                        Thread.Sleep(350);
                    else if (_entriesToZip &amp;lt; 20)
                        Thread.Sleep(200);
                    else if (_entriesToZip &amp;lt; 30)
                        Thread.Sleep(100);
                    else if (_entriesToZip &amp;lt; 45)
                        Thread.Sleep(80);
                    else if (_entriesToZip &amp;lt; 75)
                        Thread.Sleep(40);
                    // more than 75 entries, don't sleep at all.
                }
            }
        }
 
 
        private void StepEntryProgress(SaveProgressEventArgs e)
        {
            if (this.progressBar2.InvokeRequired)
            {
                this.progressBar2.Invoke(new SaveEntryProgress(this.StepEntryProgress), new object[] { e });
            }
            else
            {
                if (!_saveCanceled)
                {
                    if (this.progressBar2.Maximum == 1)
                    {
                        // reset
                        Int64 max = e.TotalBytesToTransfer;
                        _progress2MaxFactor = 0;
                        while (max &amp;gt; System.Int32.MaxValue)
                        {
                            max /= 2;
                            _progress2MaxFactor++;
                        }
                        this.progressBar2.Maximum = (int)max;
                        lblStatus.Text = String.Format(&amp;quot;{0} of {1} files...({2})&amp;quot;,
                            _nFilesCompleted + 1, _entriesToZip, e.CurrentEntry.FileName);
                    }
 
                    int xferred = e.BytesTransferred &amp;gt;&amp;gt; _progress2MaxFactor;
 
                    this.progressBar2.Value = (xferred &amp;gt;= this.progressBar2.Maximum)
                        ? this.progressBar2.Maximum
                        : xferred;
 
                    this.Update();
                }
            }
        }
 
 
 
        private void btnDirBrowse_Click(object sender, EventArgs e)
        {
            _folderName = tbDirName.Text;
            // Configure open file dialog box
            var dlg1 = new System.Windows.Forms.FolderBrowserDialog();
            //dlg1.RootFolder = &amp;quot;c:\\&amp;quot;;
            dlg1.SelectedPath = (System.IO.Directory.Exists(_folderName)) ? _folderName : &amp;quot;c:\\&amp;quot;;
            dlg1.ShowNewFolderButton = false;
 
            var result = dlg1.ShowDialog();
 
            if (result == DialogResult.OK)
            {
                _folderName = dlg1.SelectedPath;
                tbDirName.Text = _folderName;
            }
        }
 
 
        private void btnZipup_Click(object sender, EventArgs e)
        {
            KickoffZipup();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new ButtonClick(this.btnCancel_Click), new object[] { sender, e });
            }
            else
            {
                _saveCanceled = true;
                lblStatus.Text = &amp;quot;Canceled...&amp;quot;;
                ResetState();
            }
        }
 
        private void radioFlavorSfx_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioFlavorSfxGui.Checked || this.radioFlavorSfxCmd.Checked)
            {
                // Always use UTF-8 when creating a self-extractor.
                // A zip created with UTF-8 encoding is foolproof when 
                // extracted with the DotNetZip library.  The only reason you wouldn't
                // want to use UTF-8 is when your extractor doesn't support it. 
                // But DotNetZip supports it, and DotNetZip is the extractor on a SFX, 
                // so .. we'll use UTF-8 when these checkboxes are checked.  
 
                // but we will cache the current setting, so if the user clicks back
                // to the traditional zip, then he will get his favorite flavor of encoding restored. 
                if (_mostRecentEncoding == null)
                    _mostRecentEncoding = this.comboBox1.SelectedItem.ToString();
                this.comboBox1.SelectedIndex = 1; // UTF-8
                this.comboBox1.Enabled = false;
 
                // intelligently change the name of the thing to create
                if (this.tbZipName.Text.ToUpper().EndsWith(&amp;quot;.ZIP&amp;quot;))
                {
                    tbZipName.Text = System.Text.RegularExpressions.Regex.Replace(tbZipName.Text, &amp;quot;(?i:)\\.zip$&amp;quot;, &amp;quot;.exe&amp;quot;);
                }
 
                // We also do the same thing with the ZIP64 setting, for the same reason. 
                // Extracting from a ZIP64 is foolproof when DotNetZip is the extractor. 
 
                if (_mostRecentZip64 == null)
                {
                    Zip64Option x =
                    (this.radioZip64AsNecessary.Checked)
                    ? Zip64Option.AsNecessary
                    : (this.radioZip64Always.Checked)
                    ? Zip64Option.Always
                    : Zip64Option.Never;
                    _mostRecentZip64 = new Nullable&amp;lt;Zip64Option&amp;gt;(x);
                }
                this.radioZip64Always.Checked = true;
                this.radioZip64Always.Enabled = false;
                this.radioZip64AsNecessary.Enabled = false;
                this.radioZip64Never.Enabled = false;
 
            }
        }
 
        private void radioFlavorZip_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioFlavorZip.Checked)
            {
                // re-enable the encoding, and set it to what it was most recently
                this.comboBox1.Enabled = true;
                if (_mostRecentEncoding != null)
                {
                    this.SelectNamedEncoding(_mostRecentEncoding);
                    _mostRecentEncoding = null;
                }
 
                // intelligently change the name of the thing to create
                if (this.tbZipName.Text.ToUpper().EndsWith(&amp;quot;.EXE&amp;quot;))
                {
                    tbZipName.Text = System.Text.RegularExpressions.Regex.Replace(tbZipName.Text, &amp;quot;(?i:)\\.exe$&amp;quot;, &amp;quot;.zip&amp;quot;);
                }
 
                // re-enable the zip64 setting, too.
                this.radioZip64Always.Enabled = true;
                this.radioZip64AsNecessary.Enabled = true;
                this.radioZip64Never.Enabled = true;
                if (_mostRecentZip64 != null)
                {
                    if (_mostRecentZip64.Value == Zip64Option.Always)
                        this.radioZip64Always.Checked = true;
                    if (_mostRecentZip64.Value == Zip64Option.AsNecessary)
                        this.radioZip64AsNecessary.Checked = true;
                    if (_mostRecentZip64.Value == Zip64Option.Never)
                        this.radioZip64Never.Checked = true;
                    _mostRecentZip64 = null;
                }
            }
        }
 
 
        private void ResetState()
        {
            this.btnCancel.Enabled = false;
            this.btnOk.Enabled = true;
            this.btnOk.Text = &amp;quot;Zip it!&amp;quot;;
            this.progressBar1.Value = 0;
            this.progressBar2.Value = 0;
            this.Cursor = Cursors.Default;
            if (!_workerThread.IsAlive)
                _workerThread.Join();
        }
 
 
        /// This app uses the windows registry to store config data for itself. 
        ///     - creates a key for this DotNetZip Winforms app, if one does not exist
        ///     - stores and retrieves the most recent settings.
        ///     - this is done on a per user basis. (HKEY_CURRENT_USER)
        private void FillFormFromRegistry()
        {
            if (AppCuKey != null)
            {
                var s = (string)AppCuKey.GetValue(_rvn_DirectoryToZip);
                if (s != null) this.tbDirName.Text = s;
 
                s = (string)AppCuKey.GetValue(_rvn_ZipTarget);
                if (s != null) this.tbZipName.Text = s;
 
                s = (string)AppCuKey.GetValue(_rvn_Encoding);
                if (s != null)
                {
                    SelectNamedEncoding(s);
                }
 
                int x = (Int32)AppCuKey.GetValue(_rvn_ZipFlavor, 0);
                if (x == 2)
                    this.radioFlavorSfxCmd.Checked = true;
                else if (x == 1)
                    this.radioFlavorSfxGui.Checked = true;
                else
                    this.radioFlavorZip.Checked = true;
 
                x = (Int32)AppCuKey.GetValue(_rvn_Zip64Option, 0);
                if (x == 1)
                    this.radioZip64AsNecessary.Checked = true;
                else if (x == 2)
                    this.radioZip64Always.Checked = true;
                else
                    this.radioZip64Never.Checked = true;
 
 
                AppCuKey.Close();
                AppCuKey = null;
            }
        }
 
        private void SelectNamedEncoding(string s)
        {
            for (int i = 0; i &amp;lt; this.comboBox1.Items.Count; i++)
            {
                if (this.comboBox1.Items[i].ToString() == s)
                {
                    this.comboBox1.SelectedIndex = i;
                    break;
                }
            }
        }
 
 
        private void SaveFormToRegistry()
        {
            if (AppCuKey != null)
            {
                AppCuKey.SetValue(_rvn_DirectoryToZip, this.tbDirName.Text);
                AppCuKey.SetValue(_rvn_ZipTarget, this.tbZipName.Text);
                AppCuKey.SetValue(_rvn_Encoding, this.comboBox1.SelectedItem.ToString());
 
                int x = 0;
                if (this.radioFlavorSfxCmd.Checked)
                    x = 2;
                else if (this.radioFlavorSfxGui.Checked)
                    x = 1;
                AppCuKey.SetValue(_rvn_ZipFlavor, x);
 
                x = 0;
                if (this.radioZip64AsNecessary.Checked)
                    x = 1;
                else if (this.radioZip64Always.Checked)
                    x = 2;
                AppCuKey.SetValue(_rvn_Zip64Option, x);
 
                AppCuKey.SetValue(_rvn_LastRun, System.DateTime.Now.ToString(&amp;quot;yyyy MMM dd HH:mm:ss&amp;quot;));
                x = (Int32)AppCuKey.GetValue(_rvn_Runs, 0);
                x++;
                AppCuKey.SetValue(_rvn_Runs, x);
 
                AppCuKey.Close();
            }
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveFormToRegistry();
        }
 
 
        public Microsoft.Win32.RegistryKey AppCuKey
        {
            get
            {
                if (_appCuKey == null)
                {
                    _appCuKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(_AppRegyPath, true);
                    if (_appCuKey == null)
                        _appCuKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_AppRegyPath);
                }
                return _appCuKey;
            }
            set { _appCuKey = null; }
        }
 
        private string _folderName;
        private int _progress2MaxFactor;
        private int _entriesToZip;
        private bool _saveCanceled;
        private int _nFilesCompleted;
        private long _totalBytesBeforeCompress;
        private long _totalBytesAfterCompress;
        private Thread _workerThread;
        private static string TB_COMMENT_NOTE = &amp;quot;-zip file comment here-&amp;quot;;
        private List&amp;lt;String&amp;gt; _EncodingNames;
        private string _mostRecentEncoding;
        private Nullable&amp;lt;Zip64Option&amp;gt; _mostRecentZip64;
 
        private Microsoft.Win32.RegistryKey _appCuKey;
        private static string _AppRegyPath = &amp;quot;Software\\Dino Chiesa\\DotNetZip Winforms Tool&amp;quot;;
        private static string _rvn_DirectoryToZip = &amp;quot;DirectoryToZip&amp;quot;;
        private static string _rvn_ZipTarget = &amp;quot;ZipTarget&amp;quot;;
        private static string _rvn_Encoding = &amp;quot;Encoding&amp;quot;;
        private static string _rvn_ZipFlavor = &amp;quot;ZipFlavor&amp;quot;;
        private static string _rvn_Zip64Option = &amp;quot;Zip64Option&amp;quot;;
        private static string _rvn_LastRun = &amp;quot;LastRun&amp;quot;;
        private static string _rvn_Runs = &amp;quot;Runs&amp;quot;;
 
    }
 
    public class WorkerOptions
    {
        public string ZipName;
        public string Folder;
        public string Encoding;
        public string Comment;
        public int ZipFlavor;
        public Zip64Option Zip64;
    }
}
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:33:35 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: WinForms Example 20090707P</guid></item><item><title>UPDATED WIKI: WinForms Example</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms Example&amp;version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Create a ZIP within WinForms (C#)
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6502" alt="DotNetZip-Winforms-1.jpg" /&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;This is C# code for a WinForms app showing how to use DotNetZip.  I provide just the Form1.cs file here, but you can also &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2016" class="externalLink"&gt;download the full Visual Studio project&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.  Also, see the &lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=similar%20VB%20WinForms%20Example&amp;amp;referringTitle=WinForms%20Example"&gt;similar VB WinForms Example&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;Points of interest here: &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;the progress bars - there are two of them.  One is for the progress on the overall archive.  It gets updated once for each entry in the archive, as the entry is saved in the archive.  For a small archive (let's say, 100 files) this can happen very quickly.  But if you have a zip archive with 40,000 entries, this progress bar will be very helpful in showing state to the user. The second progress bar depicts the progress for the current Entry.  DotNetZip has progress events that are very fine-grained so that you can get an update on how much of the current entry has been saved (56,000 bytes out of 432,000, for example).  &lt;/li&gt;&lt;li&gt;The application also exercises many of the features of DotNetZip - for example it allows the user to employ Unicode encoding for the filenames.  Or, the user can select whether ZIP64 is used or not.  Or, the user can specify whether to create a self-extracting archive.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using Ionic.Zip;
 
namespace WinFormsExample
{
    public partial class Form1 : Form
    {
        delegate void SaveEntryProgress(SaveProgressEventArgs e);
        delegate void ButtonClick(object sender, EventArgs e);
 
        public Form1()
        {
            InitializeComponent();
 
            InitEncodingsList();
 
            FixTitle();
 
            FillFormFromRegistry();
        }
 
        private void FixTitle()
        {
            this.Text = String.Format(&amp;quot;WinForms Zip Creator Example for DotNetZip v{0}&amp;quot;,
                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
        }
 
        private void InitEncodingsList()
        {
            _EncodingNames = new List&amp;lt;string&amp;gt;();
            var e = System.Text.Encoding.GetEncodings();
            foreach (var e1 in e)
            {
                if (!_EncodingNames.Contains(e1.Name))
                    if (!_EncodingNames.Contains(e1.Name.ToUpper()))
                        if (!_EncodingNames.Contains(e1.Name.ToLower()))
                            if (e1.Name != &amp;quot;IBM437&amp;quot; &amp;amp;&amp;amp; e1.Name != &amp;quot;utf-8&amp;quot;)
                                _EncodingNames.Add(e1.Name);
            }
            _EncodingNames.Sort();
            comboBox1.Items.Add(&amp;quot;zip default (IBM437)&amp;quot;);
            comboBox1.Items.Add(&amp;quot;utf-8&amp;quot;);
            foreach (var name in _EncodingNames)
            {
                comboBox1.Items.Add(name);
            }
 
            // select the first item: 
            comboBox1.SelectedIndex = 0;
        }
 
 
 
 
        private void KickoffZipup()
        {
            _folderName = tbDirName.Text;
 
            if (_folderName == null || _folderName == &amp;quot;&amp;quot;) return;
            if (this.tbZipName.Text == null || this.tbZipName.Text == &amp;quot;&amp;quot;) return;
 
            // check for existence of the zip file:
            if (System.IO.File.Exists(this.tbZipName.Text))
            {
                var dlgResult = MessageBox.Show(String.Format(&amp;quot;The file you have specified ({0}) already exists.  Do you want to overwrite this file?&amp;quot;, this.tbZipName.Text), &amp;quot;Confirmation is Required&amp;quot;, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlgResult != DialogResult.Yes) return;
                System.IO.File.Delete(this.tbZipName.Text);
            }
 
            _saveCanceled = false;
            _nFilesCompleted = 0;
            _totalBytesAfterCompress = 0;
            _totalBytesBeforeCompress = 0;
            this.btnOk.Enabled = false;
            this.btnOk.Text = &amp;quot;Zipping...&amp;quot;;
            this.btnCancel.Enabled = true;
            lblStatus.Text = &amp;quot;Zipping...&amp;quot;;
 
            var options = new WorkerOptions
            {
                ZipName = this.tbZipName.Text,
                Folder = _folderName,
                Encoding = &amp;quot;ibm437&amp;quot;
            };
 
            if (this.comboBox1.SelectedIndex != 0)
            {
                options.Encoding = this.comboBox1.SelectedItem.ToString();
            }
 
            if (this.radioFlavorSfxCmd.Checked)
                options.ZipFlavor = 2;
            else if (this.radioFlavorSfxGui.Checked)
                options.ZipFlavor = 1;
            else options.ZipFlavor = 0;
 
            if (this.radioZip64AsNecessary.Checked)
                options.Zip64 = Zip64Option.AsNecessary;
            else if (this.radioZip64Always.Checked)
                options.Zip64 = Zip64Option.Always;
            else options.Zip64 = Zip64Option.Never;
 
            options.Comment = String.Format(&amp;quot;Encoding:{0} || Flavor:{1} || ZIP64:{2}\r\nCreated at {3} || {4}\r\n&amp;quot;,
                        options.Encoding,
                        FlavorToString(options.ZipFlavor),
                        options.Zip64.ToString(),
                        System.DateTime.Now.ToString(&amp;quot;yyyy-MMM-dd HH:mm:ss&amp;quot;),
                        this.Text);
 
            if (this.tbComment.Text != TB_COMMENT_NOTE)
                options.Comment += this.tbComment.Text;
 
 
            _workerThread = new Thread(this.DoSave);
            _workerThread.Name = &amp;quot;Zip Saver thread&amp;quot;;
            _workerThread.Start(options);
            this.Cursor = Cursors.WaitCursor;
 
        }
 
        private string FlavorToString(int p)
        {
            if (p == 2) return &amp;quot;SFX-CMD&amp;quot;;
            if (p == 1) return &amp;quot;SFX-GUI&amp;quot;;
            return &amp;quot;ZIP&amp;quot;;
        }
 
 
        private bool _firstFocusInCommentTextBox = true;
        private void tbComment_Enter(object sender, EventArgs e)
        {
            if (_firstFocusInCommentTextBox)
            {
                tbComment.Text = &amp;quot;&amp;quot;;
                tbComment.Font = new System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                tbComment.ForeColor = System.Drawing.SystemColors.WindowText;
                _firstFocusInCommentTextBox = false;
            }
        }
 
 
        private void tbComment_Leave(object sender, EventArgs e)
        {
            string TextToFind = tbComment.Text;
 
            if ((TextToFind == null) || (TextToFind == &amp;quot;&amp;quot;))
            {
                this.tbComment.Font = new System.Drawing.Font(&amp;quot;Microsoft Sans Serif&amp;quot;, 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.tbComment.ForeColor = System.Drawing.SystemColors.InactiveCaption;
                _firstFocusInCommentTextBox = true;
                this.tbComment.Text = TB_COMMENT_NOTE;
            }
        }
 
 
        private void SetProgressBars()
        {
            if (this.progressBar1.InvokeRequired)
            {
                this.progressBar1.Invoke(new MethodInvoker(this.SetProgressBars));
            }
            else
            {
                this.progressBar1.Value = 0;
                this.progressBar1.Maximum = _entriesToZip;
                this.progressBar1.Minimum = 0;
                this.progressBar1.Step = 1;
                this.progressBar2.Value = 0;
                this.progressBar2.Minimum = 0;
                this.progressBar2.Maximum = 1; // will be set later, for each entry.
                this.progressBar2.Step = 1;
            }
        }
 
 
        private void DoSave(Object p)
        {
            WorkerOptions options = p as WorkerOptions;
            try
            {
                using (var zip1 = new ZipFile())
                {
                    zip1.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(options.Encoding);
                    zip1.Comment = options.Comment;
                    zip1.AddDirectory(options.Folder);
                    _entriesToZip = zip1.EntryFileNames.Count;
                    SetProgressBars();
                    zip1.SaveProgress += this.zip1_SaveProgress;
 
                    zip1.UseZip64WhenSaving = options.Zip64;
 
                    if (options.ZipFlavor == 1)
                        zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.WinFormsApplication);
                    else if (options.ZipFlavor == 2)
                        zip1.SaveSelfExtractor(options.ZipName, SelfExtractorFlavor.ConsoleApplication);
                    else
                        zip1.Save(options.ZipName);
                }
            }
            catch (System.Exception exc1)
            {
                MessageBox.Show(String.Format(&amp;quot;Exception while zipping: {0}&amp;quot;, exc1.Message));
                btnCancel_Click(null, null);
            }
        }
 
 
 
        void zip1_SaveProgress(object sender, SaveProgressEventArgs e)
        {
            switch (e.EventType)
            {
                case ZipProgressEventType.Saving_AfterWriteEntry:
                    StepArchiveProgress(e);
                    break;
                case ZipProgressEventType.Saving_EntryBytesRead:
                    StepEntryProgress(e);
                    break;
                case ZipProgressEventType.Saving_Completed:
                    SaveCompleted();
                    break;
                case ZipProgressEventType.Saving_AfterSaveTempArchive:
                    TempArchiveSaved();
                    break;
            }
            if (_saveCanceled)
                e.Cancel = true;
        }
 
        private void TempArchiveSaved()
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new MethodInvoker(this.TempArchiveSaved));
            }
            else
            {
                lblStatus.Text = (this.radioFlavorSfxCmd.Checked || this.radioFlavorSfxGui.Checked)
                    ? &amp;quot;Temp archive saved...compiling SFX...&amp;quot;
                    : &amp;quot;Temp archive saved...&amp;quot;;
            }
        }
 
 
 
        private void SaveCompleted()
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new MethodInvoker(this.SaveCompleted));
            }
            else
            {
                lblStatus.Text = String.Format(&amp;quot;Done, Compressed {0} files, {1:N0}% of original.&amp;quot;,
                    _nFilesCompleted, (100.00 * _totalBytesAfterCompress) / _totalBytesBeforeCompress);
 
                ResetState();
            }
        }
 
 
 
        private void StepArchiveProgress(SaveProgressEventArgs e)
        {
            if (this.progressBar1.InvokeRequired)
            {
                this.progressBar1.Invoke(new SaveEntryProgress(this.StepArchiveProgress), new object[] { e });
            }
            else
            {
                if (!_saveCanceled)
                {
                    _nFilesCompleted++;
                    this.progressBar1.PerformStep();
                    _totalBytesAfterCompress += e.CurrentEntry.CompressedSize;
                    _totalBytesBeforeCompress += e.CurrentEntry.UncompressedSize;
 
                    // reset the progress bar for the entry:
                    this.progressBar2.Value = this.progressBar2.Maximum = 1;
 
                    this.Update();
 
                    // Sleep here just to show the progress bar, when the number of files is small,
                    // or when all done. 
                    // You may not want this for actual use!
                    if (this.progressBar2.Value == this.progressBar2.Maximum)
                        Thread.Sleep(350);
                    else if (_entriesToZip &amp;lt; 10)
                        Thread.Sleep(350);
                    else if (_entriesToZip &amp;lt; 20)
                        Thread.Sleep(200);
                    else if (_entriesToZip &amp;lt; 30)
                        Thread.Sleep(100);
                    else if (_entriesToZip &amp;lt; 45)
                        Thread.Sleep(80);
                    else if (_entriesToZip &amp;lt; 75)
                        Thread.Sleep(40);
                    // more than 75 entries, don't sleep at all.
                }
            }
        }
 
 
        private void StepEntryProgress(SaveProgressEventArgs e)
        {
            if (this.progressBar2.InvokeRequired)
            {
                this.progressBar2.Invoke(new SaveEntryProgress(this.StepEntryProgress), new object[] { e });
            }
            else
            {
                if (!_saveCanceled)
                {
                    if (this.progressBar2.Maximum == 1)
                    {
                        // reset
                        Int64 max = e.TotalBytesToTransfer;
                        _progress2MaxFactor = 0;
                        while (max &amp;gt; System.Int32.MaxValue)
                        {
                            max /= 2;
                            _progress2MaxFactor++;
                        }
                        this.progressBar2.Maximum = (int)max;
                        lblStatus.Text = String.Format(&amp;quot;{0} of {1} files...({2})&amp;quot;,
                            _nFilesCompleted + 1, _entriesToZip, e.CurrentEntry.FileName);
                    }
 
                    int xferred = e.BytesTransferred &amp;gt;&amp;gt; _progress2MaxFactor;
 
                    this.progressBar2.Value = (xferred &amp;gt;= this.progressBar2.Maximum)
                        ? this.progressBar2.Maximum
                        : xferred;
 
                    this.Update();
                }
            }
        }
 
 
 
        private void btnDirBrowse_Click(object sender, EventArgs e)
        {
            _folderName = tbDirName.Text;
            // Configure open file dialog box
            var dlg1 = new System.Windows.Forms.FolderBrowserDialog();
            //dlg1.RootFolder = &amp;quot;c:\\&amp;quot;;
            dlg1.SelectedPath = (System.IO.Directory.Exists(_folderName)) ? _folderName : &amp;quot;c:\\&amp;quot;;
            dlg1.ShowNewFolderButton = false;
 
            var result = dlg1.ShowDialog();
 
            if (result == DialogResult.OK)
            {
                _folderName = dlg1.SelectedPath;
                tbDirName.Text = _folderName;
            }
        }
 
 
        private void btnZipup_Click(object sender, EventArgs e)
        {
            KickoffZipup();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (this.lblStatus.InvokeRequired)
            {
                this.lblStatus.Invoke(new ButtonClick(this.btnCancel_Click), new object[] { sender, e });
            }
            else
            {
                _saveCanceled = true;
                lblStatus.Text = &amp;quot;Canceled...&amp;quot;;
                ResetState();
            }
        }
 
        private void radioFlavorSfx_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioFlavorSfxGui.Checked || this.radioFlavorSfxCmd.Checked)
            {
                // Always use UTF-8 when creating a self-extractor.
                // A zip created with UTF-8 encoding is foolproof when 
                // extracted with the DotNetZip library.  The only reason you wouldn't
                // want to use UTF-8 is when your extractor doesn't support it. 
                // But DotNetZip supports it, and DotNetZip is the extractor on a SFX, 
                // so .. we'll use UTF-8 when these checkboxes are checked.  
 
                // but we will cache the current setting, so if the user clicks back
                // to the traditional zip, then he will get his favorite flavor of encoding restored. 
                if (_mostRecentEncoding == null)
                    _mostRecentEncoding = this.comboBox1.SelectedItem.ToString();
                this.comboBox1.SelectedIndex = 1; // UTF-8
                this.comboBox1.Enabled = false;
 
                // intelligently change the name of the thing to create
                if (this.tbZipName.Text.ToUpper().EndsWith(&amp;quot;.ZIP&amp;quot;))
                {
                    tbZipName.Text = System.Text.RegularExpressions.Regex.Replace(tbZipName.Text, &amp;quot;(?i:)\\.zip$&amp;quot;, &amp;quot;.exe&amp;quot;);
                }
 
                // We also do the same thing with the ZIP64 setting, for the same reason. 
                // Extracting from a ZIP64 is foolproof when DotNetZip is the extractor. 
 
                if (_mostRecentZip64 == null)
                {
                    Zip64Option x =
                    (this.radioZip64AsNecessary.Checked)
                    ? Zip64Option.AsNecessary
                    : (this.radioZip64Always.Checked)
                    ? Zip64Option.Always
                    : Zip64Option.Never;
                    _mostRecentZip64 = new Nullable&amp;lt;Zip64Option&amp;gt;(x);
                }
                this.radioZip64Always.Checked = true;
                this.radioZip64Always.Enabled = false;
                this.radioZip64AsNecessary.Enabled = false;
                this.radioZip64Never.Enabled = false;
 
            }
        }
 
        private void radioFlavorZip_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioFlavorZip.Checked)
            {
                // re-enable the encoding, and set it to what it was most recently
                this.comboBox1.Enabled = true;
                if (_mostRecentEncoding != null)
                {
                    this.SelectNamedEncoding(_mostRecentEncoding);
                    _mostRecentEncoding = null;
                }
 
                // intelligently change the name of the thing to create
                if (this.tbZipName.Text.ToUpper().EndsWith(&amp;quot;.EXE&amp;quot;))
                {
                    tbZipName.Text = System.Text.RegularExpressions.Regex.Replace(tbZipName.Text, &amp;quot;(?i:)\\.exe$&amp;quot;, &amp;quot;.zip&amp;quot;);
                }
 
                // re-enable the zip64 setting, too.
                this.radioZip64Always.Enabled = true;
                this.radioZip64AsNecessary.Enabled = true;
                this.radioZip64Never.Enabled = true;
                if (_mostRecentZip64 != null)
                {
                    if (_mostRecentZip64.Value == Zip64Option.Always)
                        this.radioZip64Always.Checked = true;
                    if (_mostRecentZip64.Value == Zip64Option.AsNecessary)
                        this.radioZip64AsNecessary.Checked = true;
                    if (_mostRecentZip64.Value == Zip64Option.Never)
                        this.radioZip64Never.Checked = true;
                    _mostRecentZip64 = null;
                }
            }
        }
 
 
        private void ResetState()
        {
            this.btnCancel.Enabled = false;
            this.btnOk.Enabled = true;
            this.btnOk.Text = &amp;quot;Zip it!&amp;quot;;
            this.progressBar1.Value = 0;
            this.progressBar2.Value = 0;
            this.Cursor = Cursors.Default;
            if (!_workerThread.IsAlive)
                _workerThread.Join();
        }
 
 
        /// This app uses the windows registry to store config data for itself. 
        ///     - creates a key for this DotNetZip Winforms app, if one does not exist
        ///     - stores and retrieves the most recent settings.
        ///     - this is done on a per user basis. (HKEY_CURRENT_USER)
        private void FillFormFromRegistry()
        {
            if (AppCuKey != null)
            {
                var s = (string)AppCuKey.GetValue(_rvn_DirectoryToZip);
                if (s != null) this.tbDirName.Text = s;
 
                s = (string)AppCuKey.GetValue(_rvn_ZipTarget);
                if (s != null) this.tbZipName.Text = s;
 
                s = (string)AppCuKey.GetValue(_rvn_Encoding);
                if (s != null)
                {
                    SelectNamedEncoding(s);
                }
 
                int x = (Int32)AppCuKey.GetValue(_rvn_ZipFlavor, 0);
                if (x == 2)
                    this.radioFlavorSfxCmd.Checked = true;
                else if (x == 1)
                    this.radioFlavorSfxGui.Checked = true;
                else
                    this.radioFlavorZip.Checked = true;
 
                x = (Int32)AppCuKey.GetValue(_rvn_Zip64Option, 0);
                if (x == 1)
                    this.radioZip64AsNecessary.Checked = true;
                else if (x == 2)
                    this.radioZip64Always.Checked = true;
                else
                    this.radioZip64Never.Checked = true;
 
 
                AppCuKey.Close();
                AppCuKey = null;
            }
        }
 
        private void SelectNamedEncoding(string s)
        {
            for (int i = 0; i &amp;lt; this.comboBox1.Items.Count; i++)
            {
                if (this.comboBox1.Items[i].ToString() == s)
                {
                    this.comboBox1.SelectedIndex = i;
                    break;
                }
            }
        }
 
 
        private void SaveFormToRegistry()
        {
            if (AppCuKey != null)
            {
                AppCuKey.SetValue(_rvn_DirectoryToZip, this.tbDirName.Text);
                AppCuKey.SetValue(_rvn_ZipTarget, this.tbZipName.Text);
                AppCuKey.SetValue(_rvn_Encoding, this.comboBox1.SelectedItem.ToString());
 
                int x = 0;
                if (this.radioFlavorSfxCmd.Checked)
                    x = 2;
                else if (this.radioFlavorSfxGui.Checked)
                    x = 1;
                AppCuKey.SetValue(_rvn_ZipFlavor, x);
 
                x = 0;
                if (this.radioZip64AsNecessary.Checked)
                    x = 1;
                else if (this.radioZip64Always.Checked)
                    x = 2;
                AppCuKey.SetValue(_rvn_Zip64Option, x);
 
                AppCuKey.SetValue(_rvn_LastRun, System.DateTime.Now.ToString(&amp;quot;yyyy MMM dd HH:mm:ss&amp;quot;));
                x = (Int32)AppCuKey.GetValue(_rvn_Runs, 0);
                x++;
                AppCuKey.SetValue(_rvn_Runs, x);
 
                AppCuKey.Close();
            }
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveFormToRegistry();
        }
 
 
        public Microsoft.Win32.RegistryKey AppCuKey
        {
            get
            {
                if (_appCuKey == null)
                {
                    _appCuKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(_AppRegyPath, true);
                    if (_appCuKey == null)
                        _appCuKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(_AppRegyPath);
                }
                return _appCuKey;
            }
            set { _appCuKey = null; }
        }
 
        private string _folderName;
        private int _progress2MaxFactor;
        private int _entriesToZip;
        private bool _saveCanceled;
        private int _nFilesCompleted;
        private long _totalBytesBeforeCompress;
        private long _totalBytesAfterCompress;
        private Thread _workerThread;
        private static string TB_COMMENT_NOTE = &amp;quot;-zip file comment here-&amp;quot;;
        private List&amp;lt;String&amp;gt; _EncodingNames;
        private string _mostRecentEncoding;
        private Nullable&amp;lt;Zip64Option&amp;gt; _mostRecentZip64;
 
        private Microsoft.Win32.RegistryKey _appCuKey;
        private static string _AppRegyPath = &amp;quot;Software\\Dino Chiesa\\DotNetZip Winforms Tool&amp;quot;;
        private static string _rvn_DirectoryToZip = &amp;quot;DirectoryToZip&amp;quot;;
        private static string _rvn_ZipTarget = &amp;quot;ZipTarget&amp;quot;;
        private static string _rvn_Encoding = &amp;quot;Encoding&amp;quot;;
        private static string _rvn_ZipFlavor = &amp;quot;ZipFlavor&amp;quot;;
        private static string _rvn_Zip64Option = &amp;quot;Zip64Option&amp;quot;;
        private static string _rvn_LastRun = &amp;quot;LastRun&amp;quot;;
        private static string _rvn_Runs = &amp;quot;Runs&amp;quot;;
 
    }
 
    public class WorkerOptions
    {
        public string ZipName;
        public string Folder;
        public string Encoding;
        public string Comment;
        public int ZipFlavor;
        public Zip64Option Zip64;
    }
}
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:33:11 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: WinForms Example 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=19</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
DotNetZip Examples
&lt;/h1&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;Display the contents of a zip file from within a Smart Device app&amp;#63;  Show the contents of a zip file in a WinForms TreeView&amp;#63; Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more.  This set of code pages shows you how.  &lt;br /&gt;&lt;br /&gt;DotNetZip is a FREE open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;
&lt;br /&gt; &lt;br /&gt;Find out more about DotNetZip on &lt;a href="http://DotNetZip.codeplex.com/" class="externalLink"&gt;http://DotNetZip.codeplex.com/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;h2&gt;
Create a ZIP within ASP.NET 
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within WinForms (C#)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within WinForms (VB)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Create a ZIP within a Console app (C#)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4341" alt="DotNetZip2.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Show a ZIP within a TreeView in WinForms (VB)
&lt;/h2&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6498" alt="TreeViewZip-VB.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;
Examples with code
&lt;/h1&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:27:53 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: ASP.NET Example App</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET Example App&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
 &lt;br /&gt;&lt;h1&gt;
Create a ZIP within ASP.NET 
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6501" alt="DotNetZip-ASPNET.png" /&gt;&lt;br /&gt; &lt;br /&gt;And here is the download for the code for an ASPNET app that creates a zip file (C# and VB): &lt;br /&gt;&lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2015" class="externalLink"&gt;https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2015&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:25:12 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: ASP.NET Example App 20090707P</guid></item><item><title>UPDATED WIKI: ASP.NET Example App</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET Example App&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
 &lt;br /&gt;&lt;h1&gt;
Create a ZIP within ASP.NET 
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6501" alt="DotNetZip-ASPNET.png" /&gt;&lt;br /&gt; &lt;br /&gt;And here is the download for the code for an ASPNET app that creates a zip file (C#): &lt;br /&gt;&lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2015" class="externalLink"&gt;https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2015&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:23:46 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: ASP.NET Example App 20090707P</guid></item><item><title>UPDATED WIKI: TreeViewZip-VB</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Show a ZIP within a TreeView in WinForms (VB)
&lt;/h1&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6499" alt="TreeViewZip-VB.png" /&gt;&lt;br /&gt; &lt;br /&gt;This app is a VB WinForms app that displays the contents of a ZIP file in a TreeView. &lt;br /&gt; &lt;br /&gt;Below is the code for the just the Form.  The most interesting methods are AddTreeNode() and FindNodeForTag().  &lt;br /&gt; &lt;br /&gt;To get a zip of the complete Visual Studio solution, see &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2952" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿Imports Ionic.Zip
Imports System.Linq
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        PopulateTreeView()
    End Sub
 
    Private zip As Ionic.Zip.ZipFile
 
    ''' &amp;lt;summary&amp;gt;
    ''' Populates TreeView1 with the entries in the zipfile, named by TextBox1
    ''' &amp;lt;/summary&amp;gt;
    Private Sub PopulateTreeView()
        Try
            zip = ZipFile.Read(Me.TextBox1.Text)
 
            Me.TreeView1.Nodes.Clear()
            For Each e As ZipEntry In zip
                AddTreeNode(e.FileName)
            Next
 
        Catch ex As Exception
            '' eg, file does not exist, or access denied, etc
            MessageBox.Show(&amp;quot;Exception: &amp;quot; + ex.ToString(), _
                            &amp;quot;Exception during zip processing&amp;quot;, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
 
        Finally
            If Not (zip Is Nothing) Then
                zip.Dispose()
            End If
 
        End Try
    End Sub
 
    ''' &amp;lt;summary&amp;gt;
    ''' Add a node to the Treeview, for the given ZipEntry name
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the TreeNode added&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' Entries in a zip file exist in a &amp;quot;flat container space&amp;quot;: there is a single container, 
    ''' the zip file itself, that contains all entries. Even though each entry has a filename 
    ''' attached to it, and that filename may include a hierarchial directory path, the entry is 
    ''' always contained in the zipfile itself.  Even though it is possible to include directory 
    ''' entries in a zip file, those directory entries are not, themselves, containers - they do 
    ''' not contain other zip entries.  
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' This method overlays the zipentry, which exists only in a flat namespace, into a hierarchial 
    ''' tree, creating that tree from the pathname on the entry.  If the entry name is /a/b/c.txt,  
    ''' then this method adds 3 nodes to the TreeView, one for each segment in the path. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' The method is smart enough to find existing nodes matching subsegements of the path
    ''' for an entry. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;/remarks&amp;gt;
    Private Function AddTreeNode(ByVal name As String) As TreeNode
        If (name.EndsWith(&amp;quot;/&amp;quot;)) Then
            name = name.Substring(0, name.Length - 1)
        End If
        Dim node As TreeNode = FindNodeForTag(name, Me.TreeView1.Nodes)
        If Not (node Is Nothing) Then
            Return node
        End If
        Dim pnodeCollection As TreeNodeCollection
        Dim parent As String = Path.GetDirectoryName(name)
        If (parent = &amp;quot;&amp;quot;) Then
            pnodeCollection = Me.TreeView1.Nodes
        Else
            pnodeCollection = AddTreeNode(parent.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)).Nodes
        End If
        node = New TreeNode
        node.Text = Path.GetFileName(name)
        node.Tag = name ' full path
        pnodeCollection.Add(node)
        Return node
    End Function
 
    ''' &amp;lt;summary&amp;gt;
    ''' Returns the TreeNode for a given name 
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name=&amp;quot;nodes&amp;quot;&amp;gt;The TreeNodeCollection to search&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the matching TreeNode, or nothing if none exists&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' This method is used by AddTreeNode() to find existing nodes.  
    ''' &amp;lt;/remarks&amp;gt;
    Private Function FindNodeForTag(ByVal name As String, ByRef nodes As TreeNodeCollection) As TreeNode
        For Each node As TreeNode In nodes
            If (name = node.Tag) Then
                Return node
            ElseIf (name.StartsWith(node.Tag + &amp;quot;/&amp;quot;)) Then
                Return FindNodeForTag(name, node.Nodes)
            End If
        Next
        Return Nothing
    End Function
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog
 
        openFileDialog1.InitialDirectory = Me.TextBox1.Text
        openFileDialog1.Filter = &amp;quot;zip files|*.zip|EXE files|*.exe|All Files|*.*&amp;quot;
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True
 
        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            Me.TextBox1.Text = openFileDialog1.FileName
            If (System.IO.File.Exists(Me.TextBox1.Text)) Then
                Button1_Click(sender, e)
            End If
        End If
 
    End Sub
End Class
 
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:18:58 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TreeViewZip-VB 20090707P</guid></item><item><title>UPDATED WIKI: TreeViewZip-VB</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;Show a ZIP within a TreeView in WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[image:TreeViewZip-VB.png]&lt;br /&gt; &lt;br /&gt;This app is a VB WinForms app that displays the contents of a ZIP file in a TreeView. &lt;br /&gt; &lt;br /&gt;Below is the code for the just the Form.  The most interesting methods are AddTreeNode() and FindNodeForTag().  &lt;br /&gt; &lt;br /&gt;To get a zip of the complete Visual Studio solution, see &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2952" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿Imports Ionic.Zip
Imports System.Linq
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        PopulateTreeView()
    End Sub
 
    Private zip As Ionic.Zip.ZipFile
 
    ''' &amp;lt;summary&amp;gt;
    ''' Populates TreeView1 with the entries in the zipfile, named by TextBox1
    ''' &amp;lt;/summary&amp;gt;
    Private Sub PopulateTreeView()
        Try
            zip = ZipFile.Read(Me.TextBox1.Text)
 
            Me.TreeView1.Nodes.Clear()
            For Each e As ZipEntry In zip
                AddTreeNode(e.FileName)
            Next
 
        Catch ex As Exception
            '' eg, file does not exist, or access denied, etc
            MessageBox.Show(&amp;quot;Exception: &amp;quot; + ex.ToString(), _
                            &amp;quot;Exception during zip processing&amp;quot;, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
 
        Finally
            If Not (zip Is Nothing) Then
                zip.Dispose()
            End If
 
        End Try
    End Sub
 
    ''' &amp;lt;summary&amp;gt;
    ''' Add a node to the Treeview, for the given ZipEntry name
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the TreeNode added&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' Entries in a zip file exist in a &amp;quot;flat container space&amp;quot;: there is a single container, 
    ''' the zip file itself, that contains all entries. Even though each entry has a filename 
    ''' attached to it, and that filename may include a hierarchial directory path, the entry is 
    ''' always contained in the zipfile itself.  Even though it is possible to include directory 
    ''' entries in a zip file, those directory entries are not, themselves, containers - they do 
    ''' not contain other zip entries.  
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' This method overlays the zipentry, which exists only in a flat namespace, into a hierarchial 
    ''' tree, creating that tree from the pathname on the entry.  If the entry name is /a/b/c.txt,  
    ''' then this method adds 3 nodes to the TreeView, one for each segment in the path. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' The method is smart enough to find existing nodes matching subsegements of the path
    ''' for an entry. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;/remarks&amp;gt;
    Private Function AddTreeNode(ByVal name As String) As TreeNode
        If (name.EndsWith(&amp;quot;/&amp;quot;)) Then
            name = name.Substring(0, name.Length - 1)
        End If
        Dim node As TreeNode = FindNodeForTag(name, Me.TreeView1.Nodes)
        If Not (node Is Nothing) Then
            Return node
        End If
        Dim pnodeCollection As TreeNodeCollection
        Dim parent As String = Path.GetDirectoryName(name)
        If (parent = &amp;quot;&amp;quot;) Then
            pnodeCollection = Me.TreeView1.Nodes
        Else
            pnodeCollection = AddTreeNode(parent.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)).Nodes
        End If
        node = New TreeNode
        node.Text = Path.GetFileName(name)
        node.Tag = name ' full path
        pnodeCollection.Add(node)
        Return node
    End Function
 
    ''' &amp;lt;summary&amp;gt;
    ''' Returns the TreeNode for a given name 
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name=&amp;quot;nodes&amp;quot;&amp;gt;The TreeNodeCollection to search&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the matching TreeNode, or nothing if none exists&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' This method is used by AddTreeNode() to find existing nodes.  
    ''' &amp;lt;/remarks&amp;gt;
    Private Function FindNodeForTag(ByVal name As String, ByRef nodes As TreeNodeCollection) As TreeNode
        For Each node As TreeNode In nodes
            If (name = node.Tag) Then
                Return node
            ElseIf (name.StartsWith(node.Tag + &amp;quot;/&amp;quot;)) Then
                Return FindNodeForTag(name, node.Nodes)
            End If
        Next
        Return Nothing
    End Function
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog
 
        openFileDialog1.InitialDirectory = Me.TextBox1.Text
        openFileDialog1.Filter = &amp;quot;zip files|*.zip|EXE files|*.exe|All Files|*.*&amp;quot;
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True
 
        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            Me.TextBox1.Text = openFileDialog1.FileName
            If (System.IO.File.Exists(Me.TextBox1.Text)) Then
                Button1_Click(sender, e)
            End If
        End If
 
    End Sub
End Class
 
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 14:17:36 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TreeViewZip-VB 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=18</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;
DotNetZip Examples
&lt;/h2&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;Display the contents of a zip file from within a Smart Device app&amp;#63;  Show the contents of a zip file in a WinForms TreeView&amp;#63; Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more.  This set of code pages shows you how.  &lt;br /&gt;&lt;br /&gt;DotNetZip is a FREE open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;
&lt;br /&gt; &lt;br /&gt;Find out more about DotNetZip on &lt;a href="http://DotNetZip.codeplex.com/" class="externalLink"&gt;http://DotNetZip.codeplex.com/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;b&gt;ASP.NET Example&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within a Console app (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4341" alt="DotNetZip2.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Show a ZIP within a TreeView in WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=6498" alt="TreeViewZip-VB.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Examples with code
&lt;/h2&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 13:34:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=17</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;
DotNetZip Examples
&lt;/h2&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;Display the contents of a zip file from within a Smart Device app&amp;#63;  Show the contents of a zip file in a WinForms TreeView&amp;#63; Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more.  This set of code pages shows you how.  &lt;br /&gt;&lt;br /&gt;DotNetZip is a FREE open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;
&lt;br /&gt; &lt;br /&gt;Find out more about DotNetZip on &lt;a href="http://DotNetZip.codeplex.com/" class="externalLink"&gt;http://DotNetZip.codeplex.com/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;b&gt;ASP.NET Example&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within a Console app (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4341" alt="DotNetZip2.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Show a ZIP within a TreeView in WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[image:TreeViewZip-VB.jpg]&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Examples with code
&lt;/h2&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 13:33:57 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=16</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;
DotNetZip Examples
&lt;/h2&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;Display the contents of a zip file from within a Smart Device app&amp;#63;  Show the contents of a zip file in a WinForms TreeView&amp;#63; Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more.  This set of code pages shows you how.  &lt;br /&gt;&lt;br /&gt;DotNetZip is a FREE open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;&lt;br /&gt;Find out more about DotNetZip on http&amp;#58;&amp;#47;&amp;#47;DotNetZip.codeplex.com&amp;#47;. 
&lt;br /&gt; &lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;b&gt;ASP.NET Example&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within a Console app (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4341" alt="DotNetZip2.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Show a ZIP within a TreeView in WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[image:TreeViewZip-VB.jpg]&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Examples with code
&lt;/h2&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 13:17:20 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Home&amp;version=15</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;
DotNetZip Examples
&lt;/h2&gt;Need to create a zip file from within a .NET application&amp;#63; &lt;br /&gt;Do you want to unzip a zip file from within a Windows Forms application&amp;#63;  Create a zip file from within an ASP.NET page&amp;#63;  &lt;br /&gt;List the contents of a zip file from a Smart Device app&amp;#63;  Modify a .docx file programmatically&amp;#63;  Do you want to compress backups as part of a SQL Server Integration Services pipeline&amp;#63;  Zip things from a powershell script&amp;#63;  DotNetZip can help you do all of these things, and more. &lt;br /&gt;&lt;br /&gt;DotNetZip is an open-source library that enables .NET applications to read and write ZIP files. Packaged as a single assembly &amp;#40;Ionic.Zip.dll&amp;#41;, DotNetZip is a simple and easy way to include ZIP capability into your applications. &lt;br /&gt;&lt;br /&gt;DotNetZip supports many ZIP features, including password-protected files, ZIP64 files, and zipfiles with entries that have Unicode filenames or comments.  This page provides code examples for DotNetZip. &lt;br /&gt;&lt;br /&gt;Find out more about DotNetZip on http&amp;#58;&amp;#47;&amp;#47;www.codeplex.com&amp;#47;DotNetZip. 
&lt;br /&gt; &lt;br /&gt;Browse the Online reference doc &lt;a href="http://cheeso.members.winisp.net/DotNetZipHelp" class="externalLink"&gt;http://cheeso.members.winisp.net/DotNetZipHelp&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;Some example apps: &lt;br /&gt;&lt;b&gt;ASP.NET Example&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4337" alt="DotNetZip1.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4338" alt="DotNetZip.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within WinForms (VB)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4830" alt="DotNetZip-VB.jpg" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Create a ZIP within a Console app (C#)&lt;/b&gt;&lt;br /&gt;&lt;img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=DotNetZip&amp;amp;DownloadId=4341" alt="DotNetZip2.png" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Examples with code
&lt;/h2&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example%20App&amp;amp;referringTitle=Home"&gt;Create a Zip within ASP.NET&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=WinForms%20Example&amp;amp;referringTitle=Home"&gt;Create a zip within WinForms&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;amp;referringTitle=Home"&gt;Display a zip within a WinForms (VB) TreeView&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Console%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from a Console app&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=PowerShell%20Example&amp;amp;referringTitle=Home"&gt;Create a Zip from within PowerShell&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20VirtualPathProvider&amp;amp;referringTitle=Home"&gt;Deploy an ASP.NET app as a ZIP file&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=Windows%20Service%20in%20VB&amp;amp;referringTitle=Home"&gt;A Windows Service (VB) daemon that unzips files automatically&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 12:59:26 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20090707P</guid></item><item><title>UPDATED WIKI: TreeViewZip-VB</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
This is the code for the Form.  To get a zip of the complete Visual Studio solution, see &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=DotNetZip&amp;amp;ReleaseId=2952" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿Imports Ionic.Zip
Imports System.Linq
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        PopulateTreeView()
    End Sub
 
    Private zip As Ionic.Zip.ZipFile
 
    ''' &amp;lt;summary&amp;gt;
    ''' Populates TreeView1 with the entries in the zipfile, named by TextBox1
    ''' &amp;lt;/summary&amp;gt;
    Private Sub PopulateTreeView()
        Try
            zip = ZipFile.Read(Me.TextBox1.Text)
 
            Me.TreeView1.Nodes.Clear()
            For Each e As ZipEntry In zip
                AddTreeNode(e.FileName)
            Next
 
        Catch ex As Exception
            '' eg, file does not exist, or access denied, etc
            MessageBox.Show(&amp;quot;Exception: &amp;quot; + ex.ToString(), _
                            &amp;quot;Exception during zip processing&amp;quot;, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
 
        Finally
            If Not (zip Is Nothing) Then
                zip.Dispose()
            End If
 
        End Try
    End Sub
 
    ''' &amp;lt;summary&amp;gt;
    ''' Add a node to the Treeview, for the given ZipEntry name
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the TreeNode added&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' Entries in a zip file exist in a &amp;quot;flat container space&amp;quot;: there is a single container, 
    ''' the zip file itself, that contains all entries. Even though each entry has a filename 
    ''' attached to it, and that filename may include a hierarchial directory path, the entry is 
    ''' always contained in the zipfile itself.  Even though it is possible to include directory 
    ''' entries in a zip file, those directory entries are not, themselves, containers - they do 
    ''' not contain other zip entries.  
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' This method overlays the zipentry, which exists only in a flat namespace, into a hierarchial 
    ''' tree, creating that tree from the pathname on the entry.  If the entry name is /a/b/c.txt,  
    ''' then this method adds 3 nodes to the TreeView, one for each segment in the path. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' The method is smart enough to find existing nodes matching subsegements of the path
    ''' for an entry. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;/remarks&amp;gt;
    Private Function AddTreeNode(ByVal name As String) As TreeNode
        If (name.EndsWith(&amp;quot;/&amp;quot;)) Then
            name = name.Substring(0, name.Length - 1)
        End If
        Dim node As TreeNode = FindNodeForTag(name, Me.TreeView1.Nodes)
        If Not (node Is Nothing) Then
            Return node
        End If
        Dim pnodeCollection As TreeNodeCollection
        Dim parent As String = Path.GetDirectoryName(name)
        If (parent = &amp;quot;&amp;quot;) Then
            pnodeCollection = Me.TreeView1.Nodes
        Else
            pnodeCollection = AddTreeNode(parent.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)).Nodes
        End If
        node = New TreeNode
        node.Text = Path.GetFileName(name)
        node.Tag = name ' full path
        pnodeCollection.Add(node)
        Return node
    End Function
 
    ''' &amp;lt;summary&amp;gt;
    ''' Returns the TreeNode for a given name 
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name=&amp;quot;nodes&amp;quot;&amp;gt;The TreeNodeCollection to search&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the matching TreeNode, or nothing if none exists&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' This method is used by AddTreeNode() to find existing nodes.  
    ''' &amp;lt;/remarks&amp;gt;
    Private Function FindNodeForTag(ByVal name As String, ByRef nodes As TreeNodeCollection) As TreeNode
        For Each node As TreeNode In nodes
            If (name = node.Tag) Then
                Return node
            ElseIf (name.StartsWith(node.Tag + &amp;quot;/&amp;quot;)) Then
                Return FindNodeForTag(name, node.Nodes)
            End If
        Next
        Return Nothing
    End Function
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog
 
        openFileDialog1.InitialDirectory = Me.TextBox1.Text
        openFileDialog1.Filter = &amp;quot;zip files|*.zip|EXE files|*.exe|All Files|*.*&amp;quot;
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True
 
        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            Me.TextBox1.Text = openFileDialog1.FileName
            If (System.IO.File.Exists(Me.TextBox1.Text)) Then
                Button1_Click(sender, e)
            End If
        End If
 
    End Sub
End Class
 
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 12:58:24 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TreeViewZip-VB 20090707P</guid></item><item><title>CREATED RELEASE: WinForms Show Zip in TreeView (VB) (Jul 07, 2009)</title><link>http://code.msdn.microsoft.com/DotNetZip/Release/ProjectReleases.aspx?ReleaseId=2952</link><description></description><author></author><pubDate>Tue, 07 Jul 2009 12:57:09 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: WinForms Show Zip in TreeView (VB) (Jul 07, 2009) 20090707P</guid></item><item><title>UPDATED WIKI: TreeViewZip-VB</title><link>http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=TreeViewZip-VB&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
This is the code for the Form.  To get a zip of the complete Visual Studio solution, see &lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[file:FriendlyName|_file_id]. &lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
﻿Imports Ionic.Zip
Imports System.Linq
Imports System.IO
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        PopulateTreeView()
    End Sub
 
    Private zip As Ionic.Zip.ZipFile
 
    ''' &amp;lt;summary&amp;gt;
    ''' Populates TreeView1 with the entries in the zipfile, named by TextBox1
    ''' &amp;lt;/summary&amp;gt;
    Private Sub PopulateTreeView()
        Try
            zip = ZipFile.Read(Me.TextBox1.Text)
 
            Me.TreeView1.Nodes.Clear()
            For Each e As ZipEntry In zip
                AddTreeNode(e.FileName)
            Next
 
        Catch ex As Exception
            '' eg, file does not exist, or access denied, etc
            MessageBox.Show(&amp;quot;Exception: &amp;quot; + ex.ToString(), _
                            &amp;quot;Exception during zip processing&amp;quot;, _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Exclamation)
 
        Finally
            If Not (zip Is Nothing) Then
                zip.Dispose()
            End If
 
        End Try
    End Sub
 
    ''' &amp;lt;summary&amp;gt;
    ''' Add a node to the Treeview, for the given ZipEntry name
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the TreeNode added&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' Entries in a zip file exist in a &amp;quot;flat container space&amp;quot;: there is a single container, 
    ''' the zip file itself, that contains all entries. Even though each entry has a filename 
    ''' attached to it, and that filename may include a hierarchial directory path, the entry is 
    ''' always contained in the zipfile itself.  Even though it is possible to include directory 
    ''' entries in a zip file, those directory entries are not, themselves, containers - they do 
    ''' not contain other zip entries.  
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' This method overlays the zipentry, which exists only in a flat namespace, into a hierarchial 
    ''' tree, creating that tree from the pathname on the entry.  If the entry name is /a/b/c.txt,  
    ''' then this method adds 3 nodes to the TreeView, one for each segment in the path. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;para&amp;gt;
    ''' The method is smart enough to find existing nodes matching subsegements of the path
    ''' for an entry. 
    ''' &amp;lt;/para&amp;gt;
    ''' &amp;lt;/remarks&amp;gt;
    Private Function AddTreeNode(ByVal name As String) As TreeNode
        If (name.EndsWith(&amp;quot;/&amp;quot;)) Then
            name = name.Substring(0, name.Length - 1)
        End If
        Dim node As TreeNode = FindNodeForTag(name, Me.TreeView1.Nodes)
        If Not (node Is Nothing) Then
            Return node
        End If
        Dim pnodeCollection As TreeNodeCollection
        Dim parent As String = Path.GetDirectoryName(name)
        If (parent = &amp;quot;&amp;quot;) Then
            pnodeCollection = Me.TreeView1.Nodes
        Else
            pnodeCollection = AddTreeNode(parent.Replace(&amp;quot;\&amp;quot;, &amp;quot;/&amp;quot;)).Nodes
        End If
        node = New TreeNode
        node.Text = Path.GetFileName(name)
        node.Tag = name ' full path
        pnodeCollection.Add(node)
        Return node
    End Function
 
    ''' &amp;lt;summary&amp;gt;
    ''' Returns the TreeNode for a given name 
    ''' &amp;lt;/summary&amp;gt;
    ''' &amp;lt;param name=&amp;quot;name&amp;quot;&amp;gt;name of the ZipEntry&amp;lt;/param&amp;gt;
    ''' &amp;lt;param name=&amp;quot;nodes&amp;quot;&amp;gt;The TreeNodeCollection to search&amp;lt;/param&amp;gt;
    ''' &amp;lt;returns&amp;gt;the matching TreeNode, or nothing if none exists&amp;lt;/returns&amp;gt;
    ''' &amp;lt;remarks&amp;gt;
    ''' This method is used by AddTreeNode() to find existing nodes.  
    ''' &amp;lt;/remarks&amp;gt;
    Private Function FindNodeForTag(ByVal name As String, ByRef nodes As TreeNodeCollection) As TreeNode
        For Each node As TreeNode In nodes
            If (name = node.Tag) Then
                Return node
            ElseIf (name.StartsWith(node.Tag + &amp;quot;/&amp;quot;)) Then
                Return FindNodeForTag(name, node.Nodes)
            End If
        Next
        Return Nothing
    End Function
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog
 
        openFileDialog1.InitialDirectory = Me.TextBox1.Text
        openFileDialog1.Filter = &amp;quot;zip files|*.zip|EXE files|*.exe|All Files|*.*&amp;quot;
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True
 
        If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
            Me.TextBox1.Text = openFileDialog1.FileName
            If (System.IO.File.Exists(Me.TextBox1.Text)) Then
                Button1_Click(sender, e)
            End If
        End If
 
    End Sub
End Class
 
&lt;/pre&gt;
&lt;/div&gt;</description><author>Cheeso</author><pubDate>Tue, 07 Jul 2009 12:55:15 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: TreeViewZip-VB 20090707P</guid></item></channel></rss>