Removing content controls programatically using open xml

Topics: Developer Forum, User Forum
Aug 27, 2010 at 7:55 PM

Hi,

I am using content controls and open xml sdk to generate a word document from a template programatically. In the code, while replacing the content controls with the actual data i use the following code:

var regions = wordprocessingDocument.MainDocumentPart.Document.Descendants<SdtRun>().Where(run => run.SdtProperties.getFirstChild<Tag>().Val.Value == "some txt");

SdtRun first = regions.ElementAt(0);

first.Descendants<Text>().First().Text = "some value";

 

While creating the content controls in the template I have checked for Remove content control after editing option in the properties window. After the code runs and the document is generated, when I open the created document, I could find the replaced data, but the content controls are still appearing, which is not desired. I tried multiple ways but, I am unable to remove the content control programatically. Could any one please suggest me the right approach to achieve this? Any pointer would be very helpful to me.

Thanks in advance,

Laxmi