NullReferenceException on InsertHtml (DocumentBuilder)

Hi,

When we try to insert html to a Paragraph inside a StructuredDocumentTag we get a NullReferenceException.

We want to insert html inside a StructuredDocumentTag.

Here is our code:

var doc = new Aspose.Words.Document();
var builder = new Aspose.Words.DocumentBuilder(doc);
var structuredDocumentTag = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
var paragraphContainer = new Paragraph(doc);
structuredDocumentTag.AppendChild(paragraphContainer);
builder.MoveTo(paragraphContainer);
builder.InsertHtml(@"<div>&nbsp;</div>");

Can you please help us with it? (are we doing something wrong? there is a workaround?)

Thanks!

Hi Omri,

Thanks for your inquiry. Please use following highlighted line of code to get the required output. Hope this helps you.

var doc = new Aspose.Words.Document();
var builder = new Aspose.Words.DocumentBuilder(doc);
var structuredDocumentTag = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
var paragraphContainer = new Paragraph(doc);
structuredDocumentTag.AppendChild(paragraphContainer);
doc.FirstSection.Body.AppendChild(structuredDocumentTag);
builder.MoveTo(paragraphContainer);
builder.InsertHtml(@"<div>Test&nbsp;</div>");

Hi Omri,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.