Adding a new child element of type SdtContentText is indeed the solution.
I'm using the OpenXML Power Tools.
The following code is taken from here :
public static class ContentControlExtensions
{
public static IEnumerable<OpenXmlElement> ContentControls(
this OpenXmlPart part)
{
return part.RootElement
.Descendants()
.Where(e => e is SdtBlock || e is SdtRun);
}
public static IEnumerable<OpenXmlElement> ContentControls(
this WordprocessingDocument doc)
{
foreach (var cc in doc.MainDocumentPart.ContentControls())
yield return cc;
}
}
And then :
using (WordprocessingDocument doc =
WordprocessingDocument.Open(sourceFile, true))
{
foreach (var cc in doc.ContentControls())
{
SdtProperties props = cc.Elements<SdtProperties>().FirstOrDefault();
Tag tag = props.Elements<Tag>().FirstOrDefault();
SdtContentText text = props.Elements<SdtContentText>().FirstOrDefault();
if (text == null)
{
text = new SdtContentText();
text.MultiLine = new OnOffValue(true);
cc.AppendChild<SdtContentText>(text);
}
if (tag != null)
Console.WriteLine(tag.Val);
}
doc.MainDocumentPart.Document.Save();
}