none
Remove content control when contents are set by code RRS feed

  • Question

  • 'Remove content control when contents are edited' removes the content control after the content is edited manually. But it doesn't work when the contents are set from code.

    I am generating a document in the server using 'content controls' and Custom XML Part. Once the data is set and saved, document is sent to the user. Is there a way to remove 'Content Control' but keep the text before sending the document to the user.

     

    Thanks

    Ram

    Friday, May 21, 2010 3:52 PM

Answers

  • If you want to do so by code, you could move the content of the ContentControl - the descendants of SdtContent - in front of the SdtBlock Element und remove it.
    • Marked as answer by sairam100 Monday, May 24, 2010 7:51 PM
    Saturday, May 22, 2010 7:54 PM

All replies

  • If you want to do so by code, you could move the content of the ContentControl - the descendants of SdtContent - in front of the SdtBlock Element und remove it.
    • Marked as answer by sairam100 Monday, May 24, 2010 7:51 PM
    Saturday, May 22, 2010 7:54 PM
  • Thanks a lot. 

    I am getting all the SdtElements and converted to SdtBlock or SdtCell or SdtRun based on the type and then removed those after moving the content part. 

    After moving the descendants of SdtContent, i am losing the carriage return. 

     

    Any idea?

     

    Here is the code

     

    SdtContentBlock objContent = sdt.Descendants<SdtContentBlock>().FirstOrDefault();

     

                    for (int i = objContent.ChildElements.Count - 1; i > -1; i--)

                    {

                        sdt.Parent.InsertBefore(objContent.ChildElements[i].CloneNode(true), sdt);

                    }

     

                    sdt.Remove();

    Monday, May 24, 2010 8:02 PM
  • Hi,

    i made a short sample depending on your code and it did well.

    Could you be more specific about the document structure?

    Friday, May 28, 2010 9:28 AM
  • Hi,

    I have a document with Custom XML content control in it, very similar to sairam100 scenario. I am using Open XML SDK to open that word document and replace the custom XML part. when I save the document after changing the XML part, if I open the same document with Open XML, the text in XML is still the old text of content control, if I open the document using Word everything is OK, and Word show me the new values. It only update the text if I save the document in Word, then values will be updated and I can do what you said.

    Is there any way to skip the Word saving part? it means open document (by Open XML), replace the custom XML, remove content control, save the document.

    Thank you
    Mahyar

    Friday, February 3, 2012 2:19 AM