I have a Word 2013 document containing a check box control. I have set this checkbox's Tag property to fooCheckBox
:
Now I would like to programmatically find and manipulate that particular checkbox using Open XML SDK 2.5. I know how to find/enumerate checkboxes, but I don't know how to find a particular SdtContentCheckBox
by its Tag property:
Given a WordprocessingDocument doc
, how can I retrieve a specific SdtContentCheckBox
's by its Tag property?
(I have working code, which I am posting as an answer (see below). However, I have no idea if this is the right way to do it; so if someone knows a better, more proper way, I'd like to see how it's done.)
Apparently, a
SdtContentCheckBox
object's.Parent
property references aSdtProperty
collection which can be queried for aTag
descendant.I do not understand the logic behind this object modelling, but it can be used to get the job done: