Click here to Skip to main content
15,885,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friend,
I am using sandbox web-part For exporting grid data to excel sheet.
I am getting "Object reference not set to an instance of an object" Error At
Response.End()

Below is my code:

C#
Context.Response.Clear();
                   Context.Response.ContentType = "application/ms-excel";
                   Context.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
                   Context.Response.Charset = "UTF-8";
                   Context.Response.AddHeader("content-disposition", string.Format("attachment; filename=Download.xls"));

                   using (System.IO.StringWriter sw = new System.IO.StringWriter())
                   {
                       using (HtmlTextWriter htw = new HtmlTextWriter(sw))
                       {
                           ExcellExport.RenderControl(htw);
                           Context.Response.Write(htw.ToString());
                          // HttpContext.Current.Response.Write(htw.ToString());
                          Context.Response.End();
                           Context.Response.Flush();
                       }
                   }



Help Me Soon .
Thanks.
Posted
Comments
BobJanova 2-Aug-12 5:49am    
Paste the exception report and the line numbers of your code. There is no way you can be getting a null pointer exception on Context.Response.End because you've already used Context.Response several times above, so it can't be null.

1 solution

That does not seem likely. Have you stepped through to see what is in htw ? ExcellExport is the only object here I'd think could be null.
 
Share this answer
 
Comments
sugumaran srinuvasan 2-Aug-12 4:17am    
can you come again plz.. i cant get you..
Christian Graus 2-Aug-12 4:23am    
For the error to be that line, it means that between the line before and that line, Context or Response became null ( not likely ). Do you know how to use the debugger ? Have you stepped through the code ?
sugumaran srinuvasan 2-Aug-12 5:31am    
ya i have debugged the response. but i dont know how to find the place where the error occur and dont know how to fix it.. help me if u know it
Christian Graus 2-Aug-12 19:05pm    
You need to use your debugger to work out what is null. So, on the line that blows up, check to see which object is null, then work backwards to work out why.
sugumaran srinuvasan 3-Aug-12 9:10am    
is it possible to export grid in sanbox solution..?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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