ASP.NET Repsonse.Filter and ZipOutputStream

Sep 30, 2010 at 5:26 PM
Edited Sep 30, 2010 at 6:56 PM

Hello, I am using the ZipOutStream on ASP.NET's Response.Filter property.  Does this have any chance of working?

When doing the below I get You must call PutNextEntry() before calling Write().

 

[WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 public class Default : IHttpHandler
 {

  public void ProcessRequest(HttpContext context)
  {
   ZipOutputStream zipOutputStream = new ZipOutputStream(context.Response.Filter);
   zipOutputStream.Password = "mike";
   context.Response.Filter = zipOutputStream;

   context.Response.ContentType = "application/zip";
   context.Response.AddHeader("Content-Type", "application/zip");
   context.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}", "zzz.zip"));

   WebRequest webRequest = WebRequest.Create("http://www.google.com");
   WebResponse webResponse = webRequest.GetResponse();

   using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
   {
    string line;
    while ((line = streamReader.ReadLine()) != null)
    {
     context.Response.Write(line);
    }
   }

  }

  public bool IsReusable
  {
   get
   {
    return false;
   }
  }
 }

 

 

 

Coordinator
Oct 1, 2010 at 12:13 AM
Maybe. I've never tried ZipOutputStream as an aspnet filter. Also, I'm not sure I know what you're intending to accomplish. But for sure, you need to call PutNextEntry() before any calls to Write() get made. If I were you, I'd try calling PutNextEntry right after calling the ZipOutputStream constructor. Check the examples for how to do it. Good luck.