Passing Zip over webservices

Jun 9, 2010 at 6:42 PM

I am needing to ship some files over webservices. The pseudocode goes like this;

  1. The client calls the webservice method to get the files
  2. The web method
    1. Zips the files
    2. Save the zip as a stream
    3. Converts the stream to a byte array
    4. Returns the byte array.
  3. The client
    1. Converts the byte array to a zip
    2. Extracts the files from the zip

This is what I have so far: 

Ionic.Zip.ZipFile ServerZip = new Ionic.Zip.ZipFile();
string[] FilesToZip = null;
FilesToZip = System.IO.Directory.GetFiles("c:\\temp\\somefiles");
ServerZip.AddFiles(FilesToZip);
System.IO.MemoryStream ServerStream = new System.IO.MemoryStream();
ServerZip.Save(ServerStream);
byte[] FileData = ServerStream.ToArray();

Now, how do I create a new zip file using a stream or byte array? There is no New() parameters that accept a stream/byte array.

Thanks for the help!

Aaron

Jun 9, 2010 at 7:22 PM

I got my answer by perusing the discussions. I had already perused, but like most times, I think of better search terms after I post a message.

System.IO.MemoryStream ClientStream = new System.IO.MemoryStream(FileData);
Ionic.Zip.ZipFile ClientZip = Ionic.Zip.ZipFile.Read(ClientStream);
ClientZip.ExtractAll("c:\\temp\\");