Error while transferring data to Excel
-
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.
-
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.
-
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.
-
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.
What you have done?:confused: I think you removed Response.End().:confused:
Arun Jacob http://codepronet.blogspot.com/
-
What you have done?:confused: I think you removed Response.End().:confused:
Arun Jacob http://codepronet.blogspot.com/
Yes, as mentioned in that post, i used "HttpContext.Current.ApplicationInstance.CompleteRequest()" in place of Response.End()