Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error while transferring data to Excel

Error while transferring data to Excel

Scheduled Pinned Locked Moved ASP.NET
helpcsharpc++asp-netdata-structures
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nagendrathecoder
    wrote on last edited by
    #1

    Hello all, In my ASP.Net application, i am transferring GridView contents to a excel file. I am using following code:

    string attachment = "attachment; filename=MakeList.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();

    It was working fine, but as soon as i put this code in try-catch block, i am getting this error: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." If i remove try-catch block, it again works fine. Can anyone tell me whats the problem? Am i miising something? Thanks, Nagendra.

    A 1 Reply Last reply
    0
    • N nagendrathecoder

      Hello all, In my ASP.Net application, i am transferring GridView contents to a excel file. I am using following code:

      string attachment = "attachment; filename=MakeList.xls";
      Response.ClearContent();
      Response.AddHeader("content-disposition", attachment);
      Response.ContentType = "application/ms-excel";
      StringWriter sw = new StringWriter();
      HtmlTextWriter htw = new HtmlTextWriter(sw);
      GridView1.RenderControl(htw);
      Response.Write(sw.ToString());
      Response.End();

      It was working fine, but as soon as i put this code in try-catch block, i am getting this error: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." If i remove try-catch block, it again works fine. Can anyone tell me whats the problem? Am i miising something? Thanks, Nagendra.

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      Check this threads, http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/817776da-13da-43f5-a189-1727ce4f3b6b[^] http://support.microsoft.com/kb/312629/EN-US/[^]

      Arun Jacob http://codepronet.blogspot.com/

      N 1 Reply Last reply
      0
      • A Arun Jacob

        Check this threads, http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/817776da-13da-43f5-a189-1727ce4f3b6b[^] http://support.microsoft.com/kb/312629/EN-US/[^]

        Arun Jacob http://codepronet.blogspot.com/

        N Offline
        N Offline
        nagendrathecoder
        wrote on last edited by
        #3

        I tried the solution. Now i am not getting any exception but now instead of GridView contents, the whole WebPage is copied in excel file.:confused: I want only GridView contents in excel file.

        A 1 Reply Last reply
        0
        • N nagendrathecoder

          I tried the solution. Now i am not getting any exception but now instead of GridView contents, the whole WebPage is copied in excel file.:confused: I want only GridView contents in excel file.

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          What you have done?:confused: I think you removed Response.End().:confused:

          Arun Jacob http://codepronet.blogspot.com/

          N 1 Reply Last reply
          0
          • A Arun Jacob

            What you have done?:confused: I think you removed Response.End().:confused:

            Arun Jacob http://codepronet.blogspot.com/

            N Offline
            N Offline
            nagendrathecoder
            wrote on last edited by
            #5

            Yes, as mentioned in that post, i used "HttpContext.Current.ApplicationInstance.CompleteRequest()" in place of Response.End()

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups