How do you iterate through all the content controls? I have a document with several RichText content controls but the process is not finding all the content controls within the document. It appears that it is only finding content controls that are on the root and not ones that are within the body text.
Also, once I find a content control how do I replace the text?
This should be easy right?
public static void MyMethod(string docfile)
using (WordprocessingDocument doc = WordprocessingDocument.Open(docfile, true))
var docPart = doc.MainDocumentPart;
// Find the first content control whose Alias property matches the supplied name.
var sdts = docPart.Document.Descendants<SdtBlock>();
foreach (var sdt in sdts)
//todo it is not finding all content controls, it appeas they can't be with the body text
if (sdt.SdtContentBlock.InnerText == "ReplaceMeText")
//todo how to replace text: sdt.SdtContentBlock.InnerText = "MyNewText";
System.Diagnostics.Debug.WriteLine("Found" + sdt.SdtContentBlock.InnerText);