none
copy/clone/create content controls programatically RRS feed

  • Question

  • 1. How do I create a content control dynamically (on the fly)

    2. I have a content control with contents in it - word elements like paragraphs, styles and other content controls. My requirement is to copy this content control and display it with different set of data. How do I go about doing this? I tried to do a clone on SDTELEMNT  and SDTPROPERTIE of source content control, but that completly messed up ID's of the new content control. Is there a better way for me to clone/copy a content control. Or is there a way to generate new unique ID's for the content control

    Wednesday, June 30, 2010 5:16 PM

Answers

  • Hello,

    if you want to clone a content control, try to use the constructor with the OuterXml property of the content control that you want to clone like this:

    SdtBlock sdtClone = new SdtBlock(sdtToClone.OuterXml);

     

    AmineB

    Monday, July 5, 2010 7:46 AM

All replies

  • Hello,

    if you want to clone a content control, try to use the constructor with the OuterXml property of the content control that you want to clone like this:

    SdtBlock sdtClone = new SdtBlock(sdtToClone.OuterXml);

     

    AmineB

    Monday, July 5, 2010 7:46 AM
  • Don't know that this is best practice, but in a similar situation, I cloned, and then just changed the ID by incrementing

    SdtProperties.GetFirstChild<SdtId>().Val.Value


    by an arbitrary number. As I said, not sure it's the best way to do it, but it delivered the results I was after.

    Wednesday, July 7, 2010 2:52 PM