Free Support Forum -

Mail merge with ContentControls

So I’ve noticed that you now support ContentControls in the form of StructuredDocumentTags. The SDT’s in a word document also have a tag attribute visible.

I am attempting to do a mail merge from a DataTable to a template (word document).
I have only been able to find documentation on the mail merge feature being used with the “Merge Field” type. Can this work with the SDT since the SDT’s do have a tag which can be referenced it should be straightforward to do the association. The template cannot be modified due to requirements.
Using the latest version of Aspose.Words 13.3.0 not beta.


Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behaviour as MS Word do. The Mail Merge and content controls (StructuredDocumentTag) are two different features of Aspose.Words. Please read about Mail Merge in Aspose.Words from here:

The StructuredDocumentTag Class represents a structured document tag (SDT or content control) in a document. The StructuredDocumentTag.Tag property specifies a tag associated with the current SDT node. A tag is an arbitrary string which applications can associate with SDT in order to identify it without providing a visible friendly name.

You can add/modify contents of content controls (StructuredDocumentTag) by using Aspose.Words. Here is the code to insert plain text and select the Drop Down List item from the content control:

Document doc = new Document(@“c:\test\SDTs.docx”);

foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true, true))<o:p></o:p>


if (sdt.SdtType == SdtType.PlainText)<o:p></o:p>



Paragraph para = sdt.AppendChild(new Paragraph(doc)) as Paragraph; <o:p></o:p>

Run run = new Run(doc, “new text goes here”);<o:p></o:p>



else if (sdt.SdtType == SdtType.DropDownList)<o:p></o:p>


SdtListItem secondItem = sdt.ListItems[2];<o:p></o:p>

sdt.ListItems.SelectedValue = secondItem;<o:p></o:p>

} <o:p></o:p>