C1Zip not only allows you to compress files or folders into zipped files, but also provides the required methods in its API to compress long strings into memory stream.
A string variable can be saved to a zip file using one of the following methods:
Methods | Description |
OpenWriter method | The OpenWriter Method of C1ZipEntryCollection class can be used 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 | The MemoryStream method helps to 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. |
Add the following code to the Button_Click event to save string using OpenWriter method:
Add the following code to the Button_Click event to save string using MemoryStream method: