I am using the beloved DotNetZip archiving library in MVC3 to generate a Zip file on the fly which contains .png images from binaries stored in a database. I then stream the gen
Your calls to stream.Seek(0, SeekOrigin.Begin) are causing the contents of the stream to be overwritten each iteration with the most recent image data. Try this instead:
using (ZipFile zipFile = new ZipFile())
{
foreach (var userPicture in userPictures)
{
string pictureName = userPicture.Name + ".png";
using (MemoryStream tempstream = new MemoryStream())
{
Image userImage = //method that returns Drawing.Image from byte[];
userImage.Save(tempstream, ImageFormat.Png);
tempstream.Seek(0, SeekOrigin.Begin);
byte[] imageData = new byte[tempstream.Length];
tempstream.Read(imageData, 0, imageData.Length);
zipFile.AddEntry(pictureName, imageData);
}
}
zipFile.Save(Response.OutputStream);
}