We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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(@"
 
"
);
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(@"

Test 
");

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.