zip.Save(Response.OutputStream) NotSupportedException

Aug 20, 2012 at 4:38 PM
Edited Aug 20, 2012 at 4:40 PM

 

Response.Clear();
            Response.BufferOutput = false;  // for large files
            String ReadmeText = "This is a zip file dynamically generated at " + System.DateTime.Now.ToString("G");
            string filename = "test.zip";
            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "filename=" + filename);

            using (ZipFile zip = new ZipFile())
            {
                zip.AddEntry("Readme.txt", ReadmeText);
                zip.Save(Response.OutputStream);
            }
            Response.Close();
Copied with some minor changes from one of the examples. Error occurs on Zip.Save.

Stacktrace:    at System.Web.HttpResponseStream.get_Position()
   at Ionic.Zip.CountingStream..ctor(Stream stream) in c:\DotNetZip\Zip\Shared.cs:line 728

The weirdest part is it still works. After I cancel VS debugging I'm able to download the zip file and it appears to be correct.

Let me know if you need any additional info or if I'm doing something wrong. :) Thanks.
Aug 21, 2012 at 9:36 PM

After a lot of internet searching (and bashing my face in trying to use an alternative solution) I found something about seekable and nonseekable streams. So long story short this works:

var ms = new MemoryStream();
zip.Save(ms);
ms.Position = 0;
ms.CopyTo(Response.OutputStream);

 

I <3 dotnetzip. TY Cheeso.

Aug 21, 2013 at 3:21 PM
Would you be so kind as to post the code to obtain "Response". I have a general idea, but can't get it to work...
Nov 12, 2013 at 8:02 AM
I want to Save Zip file to Specific Location at Server...It works fine but save at download folder at client machine ....Please Help me..Thanks in advance
      ZipFile zip = new ZipFile();
     List<Attachment> listattachments = email.Attachments;
        int acount = attachments.Count;
        for (int i = 0; i < acount; i++)
        {
            zip.AddEntry(attachments[i].FileName, listattachments[i].Content);
        }
        Response.Clear();
        Response.BufferOutput = false;
        string zipName = String.Format("{0}.zip", message.Headers.From.DisplayName);
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
        zip.Save(Response.OutputStream);
        Response.End();