1

I have button on my page for" Export To Excel". The ButtonClick function is to export the datgrid (dgrISGrid) to excel Code is attached below: But while executing its throwing error as"thread is aborted".Whats the solution?

    protected void imgbtnExport_Click(object sender, ImageClickEventArgs e)
    {
      try
      {

        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=InformationSystems.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        dgrISGrid.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
      }
      catch (Exception ex)
      {

        ExceptionHandler ObjExceptionHandler = new ExceptionHandler();
        lblError.Text = ObjExceptionHandler.GetExceptionDetails(ex);
      }
    }

1 Answer 1

1

Response.End() causes this error.

Try using "Response.Flush()" just before this statement.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried it .Actually the messgaebox pop up comes asking to open or save.. After that the error comes.. saying the text inside is correpted. Actually my application has other export to excels also.. None of them is working.Is it the problem of excel version i have>? it is microsoft office excel 2007 on my pc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.