Cannot create zip file from a stream

Jan 29, 2014 at 5:58 AM
Edited Jan 29, 2014 at 6:27 AM
I'm using latest version of DotNetZip(v 1.9)
While creating zip file from a stream (memory stream), the resultant zip file generated cannot be extracted. I tried the default extract mechanism in windows as well as third party application like Winrar. But an bad exception is thrown 'get 0x80004005 Unspecified error'.
Following is the code I used.
               MemoryStream memoryStream;              
                using (ZipFile zipFile = new ZipFile())
                {  
                    memoryStream = new MemoryStream();
                    zipFile.AddEntry("DA.pdf", mstream);
                   
                    zipFile.Save(memoryStream);

                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.Flush();
                    File.WriteAllBytes(@"E:\\ZipLoc\\A.zip", memoryStream.ToArray());

                }
The 'mstream' is a byte array. The data in mstream is valid, as I had already checked the content of it by writing to a file.
The reason why I saved the zip to another memoryStream(a MemoryStream) is for using it for creating an attachment of a mail.
Please help.
Apr 22, 2014 at 9:05 PM
Hey, maybe this solve your problem...
Before add stream to zip file, use method Seek
var path = path.Replace(".tmp", ".zip");

                using (var zip = new ZipFile { CompressionLevel = CompressionLevel.BestSpeed })
                {
                    var cont = 0;
                    foreach (var stream in streams)
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        zip.AddEntry(string.Format("File{0}.jpg", ++cont), stream);
                    }

                    zip.Save(path);
                }