Deleting Content Controls from the Word Document in docx file RRS feed

  • Question

  • Hi everyone. 
    I'm trying to get read of the Content Controls in input docx files. Have a method to find and Delete them (below).  With it I was able to find them but when I do  SdtRun.Remove() nothing happens, and they are still there.  Not sure if where is and what I do incorrectly. 

    public void DeleteContentControls()
      MainDocumentPart main = wordDocument.MainDocumentPart;
      Console.WriteLine("Looking for Content controls to be deleted");
      IEnumerable<SdtRun> sdtElement = main.Document.Body.Descendants<SdtRun>()
      foreach (SdtRun sdtEl in sdtElement)
    public void SaveAndClose()

    Another thing is that it doesn't save any changes , through SaveAndClose method, and stops with empty error message. Probably due to the fact that no changes happening. 
    Monday, December 14, 2020 3:23 AM