title: "server cannot append header after http headers have been sent"
body: <p>i have application like email messaging system. here i adjust one solution to download all file that are in table from particular post.
   this is my code:</p>
  
  <pre><code>    protected void lbu_download_all_Click(object sender, EventArgs e)
      {
          if (rpt_file_list.Items.Count &gt; 0)
          {
              using (DataClassesDataContext db = new DataClassesDataContext())
              {
                  var query = from f in db.Files
                              where f.Post_History_id == int.Parse(post_id.Value.ToString())
                              select new
                              {
                                  FileName = f.File_name,
                                  File_ext= f.File_ext
                              };
                  foreach (var item in query)
                  {
                      System.IO.FileInfo objFile = new FileInfo(Server.MapPath("~/PostFiles/" + item.FileName.ToString() + item.File_ext.ToString()));
                      if (objFile.Exists)
                      {
                          Response.Clear();
                          string strFileName = item.FileName.ToString() + item.File_ext.ToString();
                          Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
                          Response.AddHeader("Content-Length", objFile.Length.ToString());
                          Response.ContentType = "application/octet-stream";
                          Response.WriteFile(objFile.FullName);
                          Response.BufferOutput = true; 
                          Response.Flush();
                      }
                  }
              }
          }
          else
          {
              StringBuilder sb = new StringBuilder();
              sb.Append("&lt;script type = 'text/javascript'&gt;");
              sb.Append(" No files found to download');");
              sb.Append("&lt;/script&gt;");
              ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());
          }
      }
  </code></pre>
  
  <p>i don't know what is problm please help me..</p>