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

Asked By mostafa hamdy on 24-Mar-11 07:57 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";

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

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

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:

So either ZIP the file and send it it won't give you error