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

Free Support Forum - aspose.com

Insert Document does not work for Inline Sdt


I am trying to insert document into another document using content control. I am using the method suggested on aspose documentation.Things work as expected as long as the level of content control is block. However if I place this content control inline with some text the Insert Document is not able to work as the node has to be paragraph or table …

Please suggest.



To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi Tahir,

Will prepare the console application and post shortly. I have uploaded the Inline Sdt sample. However as a quick update, I am using InsertDocument method specified on the following link.

The problem I am facing is that when a StructuredDocumentTag is specified inline, the content inside the sdt can only be run. However the below method mandates that in order to insert document, the node has to be paragraph or table.Document.zip (21.4 KB)

So I am figuring out how I can use below method if the sdt is inline

static void InsertDocument(Node insertAfterNode, Document srcDoc)
_ // Make sure that the node is either a paragraph or table._
_ if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &_
_ (!insertAfterNode.NodeType.Equals(NodeType.Table)))_
_ throw new ArgumentException(“The destination node should be either a paragraph or table.”);_




You are facing the expected behavior of Aspose.Words. You cannot insert whole document into inline content control. Please use Block level content control to get the desired output.

Thanks Tahir,

However we have a requirement wherein we need to insert text into inline Sdt from another document.

As an example, we have a template (destination document) which has content as below

Member’s Address :

This SDT will be replaced with content(address) from another document that may have address text as follows. Also this document will only have the following text

100 Summer Street, Mountain Ave, NewPort, RI - 02222

In other words, in case we are using inline SDT we may not want to insert entire document but part of it.

Please suggest how we can handle the following scenario.



In your case, we suggest you please iterate over run nodes of source document and insert them into your destination document in the content control. You can use NodeImporter.ImportNode method to import a node from one document into another.

If you still face problem, please ZIP and attach your input documents and expected output document. We will then provide you more information about your query along with code.