creating zip from subset of other zip

Oct 31, 2011 at 5:56 PM

Hi

I have a big zipfile that I need to split in multiple zip files. In the method I'm now creating I have a List<ZipEntry> object.

This is the code I have atm:

	    //All files have the same basefilename/
string
 basefilename = Path.GetFileNameWithoutExtension(entries[0].FileName);             MemoryStream memstream = new MemoryStream();             ZipFile zip = new ZipFile();             foreach (var entry in entries){                 string newFileName = basefilename + Path.GetExtension(entry.FileName);                 zip.AddEntry(newFileName, entry.OpenReader());             }                          zip.Save(memstream);
//this will later go in an file-io handler class.             FileStream outstream = File.OpenWrite(@"c:\files\"+basefilename+ ".zip");             memstream.WriteTo(outstream);             outstream.Flush();             outstream.Close();

 

And this is the error I get:

{Ionic.Zlib.ZlibException: Bad state (invalid block type)   at Ionic.Zlib.InflateManager.Inflate(FlushType flush)   at Ionic.Zlib.ZlibCodec.Inflate(FlushType flush)   at Ionic.Zlib.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count)   at Ionic.Zlib.DeflateStream.Read(Byte[] buffer, Int32 offset, Int32 count)   at Ionic.Crc.CrcCalculatorStream.Read(Byte[] buffer, Int32 offset, Int32 count)   at Ionic.Zip.SharedUtilities.ReadWithRetry(Stream s, Byte[] buffer, Int32 offset, Int32 count, String FileName)   at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)   at Ionic.Zip.ZipEntry.Write(Stream s)   at Ionic.Zip.ZipFile.Save()   at Ionic.Zip.ZipFile.Save(Stream outputStream)   at Getronics.Domain.Services.Cuc4XXService.processCuc4xForm(List`1 entries, String tokenId, String relationId) in C:\projects\getronics\Getronics.Domain\Services\Cuc4XXService.cs:line 448   at Getronics.Domain.Services.Cuc4XXService.parseZipFile(ZipFile zipFile, String tokenId, String relationId) in C:\projects\getronics\Getronics.Domain\Services\Cuc4XXService.cs:line 377}

What am I doing wrong?

Patrick

Coordinator
Nov 7, 2011 at 4:26 PM

I answered this on StackOverflow.

See here: http://stackoverflow.com/questions/7959211/dotnetzip-creating-zip-from-subset-of-other-zip