首页 > 解决方案 > 为什么我得到 ObjectReference 空错误,而参数有一个值?

问题描述

这是我的代码,为什么会产生错误?

 sMailBody=MailstrBody.ToString();
                    StringBuilder sample = new StringBuilder();
                    sample = MailstrBody;

                                           string passno = dsMail1.Tables[0].Rows[0]["PASSNO"].ToString();
                    HttpResponse Response = HttpContext.Current.Response;

                    EmailContentDAL example = new EmailContentDAL();
                    example.Pdf(sample, Response, passno);      


     public void Pdf(StringBuilder sample, HttpResponse currentResponse, string passno)
    {

      StringReader sr = new StringReader(sample.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, 
        currentResponse.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
       currentResponse.Clear();
       currentResponse.ContentType = "application/pdf";
       currentResponse.AddHeader("Content-Disposition", "attachment; filename=GetPass_" + passno + ".pdf");

        currentResponse.Buffer = true;
        currentResponse.Cache.SetCacheability(HttpCacheability.NoCache);
        currentResponse.Write(pdfDoc);
        currentResponse.End();

}

上面的代码在 处产生空引用错误htmlparser.Parse(sr),但在 处StringReader sr = new StringReader(sample.ToString())显示sample.toString()一个值。

标签: c#asp.netc#-4.0

解决方案


推荐阅读