We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

AppendHtml throws nullreferenceexception

Thread ID:

Created:

Updated:

Platform:

Replies:

144648 May 15,2019 05:08 PM UTC May 17,2019 11:55 AM UTC ASP.NET MVC 5
loading
Tags: DocIO
Péter N
Asked On May 15, 2019 05:38 PM UTC

DocIO throws nullreference exception when I try to append Html content to a paragraph.
I am near deadline, which version is working?

  a következő helyen: Syncfusion.DocIO.DLS.HTMLConverterImpl.AppendToTextBody(ITextBody textBody, String html, Int32 paragraphIndex, Int32 paragraphItemIndex)
   a következő helyen: Syncfusion.DocIO.DLS.HTMLConverterImpl.AppendToTextBody(ITextBody textBody, String html, Int32 paragraphIndex, Int32 paragraphItemIndex, IWParagraphStyle style, ListStyle listStyle)
   a következő helyen: Syncfusion.DocIO.DLS.WParagraph.AppendHTML(String html)
   a következő helyen: Controllers.HomeController.Index() hely: HomeController.cs, sor: 324
   a következő helyen: lambda_method(Closure , ControllerBase , Object[] )
   a következő helyen: System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   a következő helyen: System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   a következő helyen: System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   a következő helyen: System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   a következő helyen: System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_0.b__0()
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_2.b__2()

EDIT: additional info, the code:

var par = new WParagraph(wordDocument);
par.AppendHTML(Content);

Thanks,
 Peter

Mohanaselvam  Jothi [Syncfusion]
Replied On May 16, 2019 05:19 AM UTC

Hi Peter,

Thank you for contacting Syncfusion support.

From the given details, we suspect that the issue might be specific to the HTML content used at your end. So, could you please share us the HTML content which used at your end. Thereby, we will check on the reported problem and provide you the solution at the earliest.

Note: If you have any confidential data in you HTML,
you can also mail the file to our Syncfusion support through support@syncfusion.com.

Regards,
Mohanaselvam J


Péter N
Replied On May 16, 2019 07:29 AM UTC

Thank you for the response. You can try this:

using Syncfusion.DocIO.DLS;

namespace DocIONull
{
    class Program
    {
        static void Main(string[] args)
        {
            WordDocument document = new WordDocument();
            document.EnsureMinimal();
            document.AddSection().AddParagraph().AppendText("#TEST#");
            IWParagraph paragraph = new WParagraph(document);
            paragraph.AppendHTML("<p>NullReferenceException</p>");
            TextBodyPart bodyPart = new TextBodyPart(document);
            bodyPart.BodyItems.Add(paragraph);
            document.Replace("#TEST#", bodyPart, true, true);
            document.Save("null.docx");
        }
    }
}


Mohanaselvam  Jothi [Syncfusion]
Replied On May 16, 2019 09:11 AM UTC

Hi Peter,

Thank you for sharing us the details.

When appending HTML content in paragraph, the HTML content may contain multiple paragraphs, tables or other body items. Essential DocIO appends the HTML contents (multiple paragraphs, tables) following with the current paragraph in body of Word document, which is one of the behavior in appending HTML contents. The reported problem occurs due to appending new paragraph (from HTML content) with the paragraph which doesn’t linked with the body of the Word document.


To append the HTML with Word document, we suggest you to append the HTML contents after linked with body of the Word document. Thus, it appends the body items along with existing body items in the TextBodyPart properly. Please refer the below highlighted code example to resolve the problem at your end:
 
WordDocument document = new WordDocument(); 
document.EnsureMinimal(); 
document.AddSection().AddParagraph().AppendText("#TEST#"); 
IWParagraph paragraph = new WParagraph(document); 
TextBodyPart bodyPart = new TextBodyPart(document); 
bodyPart.BodyItems.Add(paragraph); 
paragraph.AppendHTML("<p>NullReferenceException</p>"); 
document.Replace("#TEST#", bodyPart, true, true); 
document.Save("null.docx"); 


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


Péter N
Replied On May 16, 2019 11:01 AM UTC

Thank you!

Suggestion:
Handle this situation and throw InvalidOperationException("Any helpfull message") when someone tries to append HTML before the paragraph attached.

Regards,
 Peter

Mohanaselvam  Jothi [Syncfusion]
Replied On May 17, 2019 11:55 AM UTC

Hi Peter,

Thank you for your suggestions. We will consider your feedback as a valid request and will handle this scenario.
We don’t have any immediate plans to implement this at our end. We will implement this in any of our upcoming releases.

Please let us know if you have any other questions.
 
 
Regards, 
Mohanaselvam J 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon