ComponentOne Zip for .NET
Zip for .NET Task-Based Help / Compressing Datasets
In This Topic
    Compressing Datasets
    In This Topic

    To write a dataset into a compressed zip file, use the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub SaveDataSet(ds As DataSet)
        ' Open/create zip file.
        Dim zip As New C1.C1Zip.C1ZipFile()
        zip.Open("c:\temp\dataset.zip")
        ' Write the dataset into the zip file.
        Dim s As Stream = zip.Entries.OpenWriter(ds.DataSetName, True)
        Try
            ds.WriteXml(s, XmlWriteMode.WriteSchema)
        Finally
            s.Dispose()
        End Try
    End Sub
    Private Sub CheckDataSet(ds As DataSet)
        ' Open/create zip file.
        Dim zip As New C1.C1Zip.C1ZipFile()
        zip.Open("c:\temp\dataset.zip")
        ' Read the dataset from the zip file.
        Dim dsTest As New DataSet(ds.DataSetName) '
        Dim s As Stream = zip.Entries(ds.DataSetName).OpenReader()
        Try
            dsTest.ReadXml(s)
        Finally
            s.Dispose()
        End Try
        ' Check that the datasets are equivalent.
        Dim i As Integer
        For i = 0 To ds.Tables.Count - 1
            Dim dt1 As DataTable = ds.Tables(i)
            Dim dt2 As DataTable = dsTest.Tables(i)
            Debug.Assert((dt1.TableName = dt2.TableName And dt1.Columns.Count = dt2.Columns.Count And dt1.Rows.Count = dt2.Rows.Count))
        Next i
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void SaveDataSet(DataSet ds)
    {
         // Open/create zip file.
        C1.C1Zip.C1ZipFile zip = new C1.C1Zip.C1ZipFile();
        zip.Open(@"c:\temp\dataset.zip");
     
        // Write the dataset into the zip file.
        using (Stream s = zip.Entries.OpenWriter(ds.DataSetName, true))
        {
            ds.WriteXml(s, XmlWriteMode.WriteSchema);
        }
    }
    private void CheckDataSet(DataSet ds)
    {
        // Open/create zip file.
        C1.C1Zip.C1ZipFile zip = new C1.C1Zip.C1ZipFile();
        zip.Open(@"c:\temp\dataset.zip");
     
        // Read the dataset from the zip file.
        DataSet dsTest = new DataSet(ds.DataSetName);
        using (Stream s = zip.Entries[ds.DataSetName].OpenReader())
        {
            dsTest.ReadXml(s);
        }
     
        // Check that the datasets are equivalent.
        for (int i = 0; i < ds.Tables.Count; i++)
        {
            DataTable dt1 = ds.Tables[i];
            DataTable dt2 = dsTest.Tables[i];
            System.Diagnostics.Debug.Assert(dt1.TableName == dt2.TableName && dt1.Columns.Count == dt2.Columns.Count && dt1.Rows.Count == dt2.Rows.Count);
        }
    }