title: System.Threading.ThreadAbortException occurred in mscorlib.dll occuring persitently
body: <p>Im new to .net,
  Im using the following code to transfer from gridview to excel:</p>
  
  <pre><code>         protected void toexcelbutton_Click(object sender, EventArgs e)
          {
         Response.ClearContent();
      Response.Buffer = true;
      Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "attendancedatereport.xls"));
      Response.ContentType = "application/ms-excel";
      StringWriter sw = new StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      GridView1.AllowPaging = false;
      GridView1.AllowSorting = false;
      GridView1.DataBind();
      HtmlForm htmfrm = new HtmlForm();
      GridView1.Parent.Controls.Add(htmfrm);
      htmfrm.Attributes["runat"] = "server";
      htmfrm.Controls.Add(GridView1);
      htmfrm.RenderControl(htw);
      Response.Write(sw.ToString());
  
      HttpContext.Current.ApplicationInstance.CompleteRequest();
  }
  </code></pre>
  
  <p>When i run this code,i get an exception:</p>
  
  <p>A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll.</p>
  
  <p>But,when i run the same code in another page for another gridview,it works perfectly.,i tried,adding</p>
  
  <pre><code>EnableEventValidation="false"
  </code></pre>
  
  <p>to the aspx page, and</p>
  
  <pre><code>&lt;pre lang="cs"&gt;public override void VerifyRenderingInServerForm(Control control)
  {
     /* Verifies that the control is rendered */
  }&lt;/pre&gt;
  </code></pre>
  
  <p>to the aspx.cs page,</p>
  
  <p>i tried clearing the temporary files, still i get the same error,for more than 5hours i have tried,nothing is working.</p>
  
  <p>I then tried select the <strong>Debug</strong> -> <strong>Exceptions</strong> menu item, and in the dialog that appears, checked the first checkbox for "Common Language Runtime Exceptions,</p>
  
  <p>i get this error:</p>
  
  <blockquote>
    <p>Access to the path 'C:\Users\abcd\AppData\Local\Temp\Temporary ASP.NET Files\mark\3f229106\f785abea\App_Web_0h5ppn4m.dll' is denied.</p>
  </blockquote>