ASP.NET - Server cannot append header after HTTP headers have been send

Asked By mostafa hamdy on 24-Mar-11 07:55 AM

Hello all
I have http handler which is making download for list of files , but when I call this handler from mt web page and pass list of objects contains the file to be downloaded , It just allow to download the first file in the list but with the second file in list I get the following error "Server cannot append header after HTTP headers have been send" my code is as the following :
foreach(fileobject obj in lstfiles)
   {

        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + obj.Filename));
         context.Response.AddHeader("Content-Length", obj.Length.ToString());
         context.Response.ContentType = "application/octet-stream";
          context.Response.WriteFile(obj.CompleteFilename);

        context.Response.Flush();
        context.Response.Close();
   }
please if any body get what I mean and can help me in solving this issue please send me or tell me about some URL may help me in solving it
regards
Mostafa

Mihir Soni replied to mostafa hamdy on 24-Mar-11 08:10 AM
Hello,

Due to the limitations of the http protocol, you can only send one file per request.  

Therefore, you will need to pack the separate files into one package (zip, for example) and send that.  Something like this should help get you started
http://weblogs.asp.net/dneimke/archive/2005/02/25/380273.aspx