Interacting with StructuredDocumentTags

Is it possible to interact with existing StructuredDocumentTags? If so, how is it done? I would like to be able to insert plain text, select an item in a drop down list, and check/uncheck a checkbox. Here’s what I have so far:

foreach(var item in wordDoc.GetChildNodes(NodeType.StructuredDocumentTag, true, true))
{
    var sdt = (StructuredDocumentTag) item;

    switch (sdt.SdtType)
    {
        case SdtType.PlainText:
            // Insert text

        case SdtType.DropDownList:
            // Select an item

        case SdtType.Checkbox:
            // Check/uncheck the checkbox
    }
}

Thanks,
Randy

Hi Randy,

Thanks for your inquiry. Yes, you can interact with content controls by using StructuredDocumentTag class. 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))
{
    if (sdt.SdtType == SdtType.PlainText)
    {
        sdt.RemoveAllChildren();
        Paragraph para = sdt.AppendChild(new Paragraph(doc)) as Paragraph;
        Run run = new Run(doc, "new text goes here");
        para.AppendChild(run);
    }
    else if (sdt.SdtType == SdtType.DropDownList)
    {
        SdtListItem secondItem = sdt.ListItems[2];
        sdt.ListItems.SelectedValue = secondItem;
    }
}
doc.Save(@"c:\test\out.docx");

I hope, this will help.

Moreover, could you please attach your Word document that contains the CheckBox Control? I will closely look into it and provide you code snippet.

Best Regards

Thanks, these examples work great. I’ve attached a document with the checkbox element I was referring to.

Hi
Randy,

Thanks for your inquiry. I am afraid, currently there is no way you can change the state of CheckBox control to checked/unchecked. I have logged a new feature request in our bug tracking system. The issue ID is WORDSNET-6502. Your request has also been linked to this issue and you will be notified as soon as it is supported. Sorry for the inconvenience.

Best Regards,

The issues you have found earlier (filed as WORDSNET-6502) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)