在Sanbox Solution中,对象引用未设置为对象的实例 [英] Object reference not set to an instance of an object at Sanbox Solution

查看:84
本文介绍了在Sanbox Solution中,对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我正在使用沙箱Web部件将网格数据导出到Excel工作表.
我收到对象引用未设置为对象的实例"的错误,在
Response.End()

以下是我的代码:

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:

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.

推荐答案

这似乎不太可能.您是否已逐步了解htw中的内容? ExcellExport是我认为这里可能为null的唯一对象.
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.


这篇关于在Sanbox Solution中,对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆