Saving a String Variable to a Zip File

To save a string variable to a zip file, use one of the following methods:

      C1ZipEntryCollection.OpenWriter method

Use the OpenWriter method to get a stream writer, write the string into it, and then close it. The data is compressed as you write it into the stream, and the whole stream is saved into the zip file when you close it.

      MemoryStream method

Use a MemoryStream method; write the data into it, and then add the stream to the zip file. Note that this method requires a little more work than the OpenWriter method, but is still very manageable.

The following code shows both methods. In this example, the code for the OpenWriter method is shown in the button1_Click event. The code for the MemoryStream method is shown in the button2_Click event.

      C#


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.