I have a word file that have multy Rich Text Content Control
I want to change text of it. I Use this code .
using (WordprocessingDocument theDoc =
You only retrieve and update the first Text of your sdtContent. To replace all of it, the simples way is:
Update your code with:
if (alias != null)
{
// delete all paragraph of the sdt
sdt.Descendants<Paragraph>().ToList().ForEach(p => p.Remove());
// insert your new text, who is composed of:
// - A Paragraph
// - A Run
// - A Text
sdt.Append(new Paragraph(new Run(new Text("As a consultant his job is to design, develop and love poney."))));
}
edit: I forget to add the paragraph and the run
You can see how is build a SdtContent here https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sdtcontentblock(v=office.14).aspx