Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7710165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:03:09+00:00 2026-06-01T01:03:09+00:00

I have 5 MemoryStreams. I want to create a new zip (Which will also

  • 0

I have 5 MemoryStreams. I want to create a new zip (Which will also be a Stream) while each of the 5 MemoryStreams I have, will respresnt a file.

I do have this code about how to Zip a string/1 MemoryStream.

public static string Zip(string value)
{
    //Transform string into byte[]  
    byte[] byteArray = new byte[value.Length];
    int indexBA = 0;
    foreach (char item in value.ToCharArray())
    {
        byteArray[indexBA++] = (byte)item;
    }

    //Prepare for compress
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
        System.IO.Compression.CompressionMode.Compress);

    //Compress
    sw.Write(byteArray, 0, byteArray.Length);
    //Close, DO NOT FLUSH cause bytes will go missing...
    sw.Close();

    //Transform byte[] zip data to string
    byteArray = ms.ToArray();
    System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
    foreach (byte item in byteArray)
    {
        sB.Append((char)item);
    }
    ms.Close();
    sw.Dispose();
    ms.Dispose();
    return sB.ToString();
}

This code is good, But I need some kind of separation between the MemoryStreams. I don’t want them to be consecutive. (Preferably I’d like them to be on different files within the ZipStream)

How can I create files (or a similar separator) within the ZipStream?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:03:11+00:00Added an answer on June 1, 2026 at 1:03 am

    GZipStream in the .net library is not really geared up for creating zip files. It’s main purpose is to compress a stream which could be for sending data or in your example above streaming to a file.

    Compressed GZipStream objects written to a file with an extension of
    .gz can be decompressed using many common compression tools; however,
    this class does not inherently provide functionality for adding files
    to or extracting files from .zip archives.

    You can get the GZip library to create a zip file with multiple compressed files but it will require some legwork on your part. There is a blog post here that shows you how to do it.

    However there are some other solutions you could consider:

    1. SharpZipLib is a free and widely used compression library. The link provided is to the wiki which shows you how to compress and decompress. You can de/compress from and to files or streams.
    2. .net 3 has a packaging library which you could look at. One thing to note is it will contain meta data. Also this library cannot open zip files which do not contain the meta data. The link provided has an example at the bottom on how to compress multiple files.
    3. There are other libraries out that are free but I have not used them.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I want to create a .csv file in C#. I have been looking
I have a method which returns some xml in a memory stream private MemoryStream
We're trying to create a .NET aspx page that will have a PDF within
I want to create a file with a .aspx extension(or any other extension) completely
I have four MemoryStreams of data that I want to merge and then open
I want to create a Text file in my code behind file in my
I have some code that does MemoryStream ms = new MemoryStream(); ... return Image.FromStream(ms);
I have a simple code byte[] buffer = Encoding.UTF8.GetBytes(abracadabra); MemoryStream ms = new MemoryStream();
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.