Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi dear all

My task is to download an excel file the data which is retrieved frm DB..

I tried with the code ....

The same code which is running in 3 form and not in a 1 specific form alone and am getting the error as

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Here is my code

pls Help me whith dis

XML
// HttpResponse response = HttpContext.Current.Response;
          Response.Clear();
          Response.Buffer = true;
          Response.ContentType = "application/vnd.ms-excel";
          Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".xls");
        //  Response.Charset = "utf-8";
          Response.Charset = "";
          Response.ContentType = "application/vnd.ms-excel";
          //Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
          //Response.Write("<font style='font-size:11.0pt; font-family:Calibri;'>");
          //Response.Write("<BR><BR><BR>");

          using (StringWriter StrWrtr = new StringWriter())
          {
              using (HtmlTextWriter HtmlWrtr = new HtmlTextWriter(StrWrtr))
              {

                  gvexcel.HeaderRow.BackColor = Color.Gray;

                  int ColumnCount = gvexcel.Columns.Count;

                
                  for (int i = 0; i <= ColumnCount - 1; i++)
                  {
                  
                      Response.Write(gvexcel.Columns[i].HeaderText.ToString());
                      Response.Write("<B>");
                  }
                 // Response.Write("</Font>");
                  gvexcel.RenderControl(HtmlWrtr);

                  string style = @"<style> .textmode { mso-number-format:\@; } </style>";

                  Response.Write(style);
                  Response.Output.Write(StrWrtr.ToString());
                  Response.Flush();

                 // HttpContext.Current.ApplicationInstance.CompleteRequest();
                  Response.End();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900