2

I'm needing to create a zipped document containing files that exist on the server. I am using the Ionic.Zip to do so, and to create a new Package (which is the zip file) I have to have either a path to a physical file or a stream. I am trying to not create an actual file that would be the zip file, instead just create a stream that would exist in memory or something. how can i do this?

3 Answers 3

1

Create the package using a MemoryStream then.

Sign up to request clarification or add additional context in comments.

Comments

1

You can try the save method in the ZipFile Class. It can save to a stream try this.

using (MemoryStream ms = new MemoryStream())
{
 using (Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile())
 {
   zipFile.AddFiles(filesToBeZipped, false, "NewFolder");//filesTobeZipped is a List<string>
   zipFile.Save(ms);
  }
}

3 Comments

Vignesh Natraj : where is this zip file saving, what is the meaning of this new folder. if you can give answer asap it will be great help to me
you can check the method signature for AddFiles,"NewFolder" is the folder structure inside the Compressed Zip file, I am telling the method to put all files inside a folder called NewFolder.
and it'll save to the memory stream like you asked.
1

You'll want to use the .AddEntry method on the ZipFile you've created specifying a name and the byte[] containing the actual file data.

ex.

    ZipFile zipFile = new ZipFile();
    zipFile.AddEntry(file.FileName, file.FileData);

where file.FileName will be the entry name (in the zip file) and file.FileData is the byte array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.