ComponentOne Zip for .NET
Zip for .NET Task-Based Help / Creating a Zip File with Multiple Entries
In This Topic
    Creating a Zip File with Multiple Entries
    In This Topic

    To stream multiple XML files directly into the zip file, use the OpenWriter method. That returns a stream that you can write to, and when the stream is closed it is added to the zip file.

    Add the following code to the Click event:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim zip As New C1ZipFile()
        zip.Create("c:\temp\test.zip") 
        Dim s As Stream = zip.Entries.OpenWriter("entry1", True)
        Dim sw As New StreamWriter(s)
        sw.WriteLine("Hello world")
         ' Continue writing as much as you want...
        sw.Close()
        s = zip.Entries.OpenWriter("entry2", True)
        sw = New StreamWriter(s)
        sw.WriteLine("Hello again")
         ' Continue writing as much as you want...
        sw.Close()
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void button1_Click(object sender, System.EventArgs e)
    {
        C1ZipFile zip = new C1ZipFile();
        zip.Create(@"c:\temp\test.zip");
        Stream s = zip.Entries.OpenWriter("entry1", true);
        StreamWriter sw = new StreamWriter(s);
        sw.WriteLine("Hello world");
          // Continue writing as much as you want...
        sw.Close();
        s = zip.Entries.OpenWriter("entry2", true);
        sw = new StreamWriter(s);
        sw.WriteLine("Hello again");
          // Continue writing as much as you want...
        sw.Close();
    }
    

    To read an entry without saving it to a file, use the OpenReader method on the entry object.

    Note: OpenWriter is a member of the C1ZipEntryCollection class, while OpenReader is a member of the C1ZipEntry class.