Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Compress .NET Stream

To compress a .NET stream, do the following:

  1. Create a ZipArchive class instance.
  2. Call its ZipArchive.AddStream method and specify a source stream.
  3. Call the proper ZipArchive.Save method overload to create an archive and save it to a stream.

View Example

using DevExpress.Compression;

public void ArchiveStream() {
    using (Stream myStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("DevExpress"))) {
        using (Stream myZippedStream = new FileStream("ArchiveStream.zip", System.IO.FileMode.Create)) {
            using (ZipArchive archive = new ZipArchive()) {
                archive.AddStream("myStream", myStream);
                archive.Save(myZippedStream);
            }
        }
    }
}