This project is read-only.

Issues with zipping a stream and passing that stream on

Aug 25, 2010 at 9:21 PM

I'm having problems zipping a file passed as a stream and moving that stream on its way.

I'm writing the stream as an email attachment. The attachment is there, but the contents are unreadable.


Here's my code: 

ms = New MemoryStream()                        

ms.Write(attDoc, 0, attDoc.Length)                      

ms.Seek(0, SeekOrigin.Begin)                      

Dim ZipFile = New ZipFile()                                 

ZipFile.AddEntry("etc.doc", ms)                            


email.Attachments.Add("", ms)


Any help would be appreciated.



Aug 26, 2010 at 12:09 AM

Your code looks a little confused. 

From what I see, your code does this: 1. Write some data to a stream.  2. Seek in that stream to the beginning.  3. Open a zip file. 4. Add an entry to the zip file, specifying the stream from step 1.  5. Save the zip file to the same stream. ???

The problem is step 5.  You are overwriting the source stream.  If you want to create a memory stream that contains a zip file, then create a NEW memoryStream that receives the zip content.  Any entries added to the zipfile should use unique streams. 

Good luck. 


Aug 27, 2010 at 2:33 PM

I completely missed the fact that I was overwriting the stream. Darn code blindness.

I used a second stream, seek to 0 on that stream and everything is working.