wordpress hit counter
Welcome to OpenXML Developer Sign in | Join | Help

How to get all content controls and insert html using altchunk

Last post 01-29-2010, 1:16 PM by mac73. 0 replies.
Sort Posts: Previous Next
  •  01-29-2010, 1:16 PM 8065

    How to get all content controls and insert html using altchunk

    Hi,
    I was working on an example provided by Eric White as i have similar requirements.

    I dont get Source1 when i put that i a paragraph

    Here is my word document
    <w:document >
    <w:body>
    <w:p w:rsidR="00F24910" w:rsidRDefault="00306DA0" w:rsidP="00C615CF">
    <w:pPr>
    <w:pStyle w:val="Title"/>
    <w:outlineLvl w:val="0"/>
    </w:pPr>
    <w:r>
    <w:t>Word Document Set Template</w:t>
    </w:r>
    </w:p>
    <w:p w:rsidR="0069030A" w:rsidRDefault="007C6472" w:rsidP="007C6472">
    <w:pPr>
    <w:tabs>
    <w:tab w:val="left" w:pos="2520"/>
    </w:tabs>
    </w:pPr>
    <w:r>
    <w:t xml:space="preserve">This is same test: </w:t>
    </w:r>
    <w:sdt>
    <w:sdtPr>
    <w:alias w:val="Source1"/>
    <w:tag w:val="Source1"/>
    <w:id w:val="1835618169"/>
    <w:placeholder>
    <w:docPart w:val="42C39213AF0844B5A5E1CA8FA4211885"/>
    </w:placeholder>
    <w:showingPlcHdr/>
    <w:text/>
    </w:sdtPr>
    <w:sdtContent>
    <w:r w:rsidR="0069030A" w:rsidRPr="000A5EE9">
    <w:rPr>
    <w:rStyle w:val="PlaceholderText"/>
    </w:rPr>
    <w:t>Click here to enter text.</w:t>
    </w:r>
    </w:sdtContent>
    </w:sdt>
    <w:r>
    <w:tab/>
    </w:r>
    </w:p>
    <w:sdt>
    <w:sdtPr>
    <w:alias w:val="Source2"/>
    <w:tag w:val="Source2"/>
    <w:id w:val="1835618176"/>
    <w:placeholder>
    <w:docPart w:val="25A1D5BF102D4544BAE51F5F671DF617"/>
    </w:placeholder>
    <w:showingPlcHdr/>
    <w:text/>
    </w:sdtPr>
    <w:sdtContent>
    <w:p w:rsidR="0069030A" w:rsidRDefault="0069030A" w:rsidP="0069030A">
    <w:r w:rsidRPr="000A5EE9">
    <w:rPr>
    <w:rStyle w:val="PlaceholderText"/>
    </w:rPr>
    <w:t>Click here to enter text.</w:t>
    </w:r>
    </w:p>
    </w:sdtContent>
    </w:sdt>
    <w:sdt>
    <w:sdtPr>
    <w:alias w:val="Source3"/>
    <w:tag w:val="Source3"/>
    <w:id w:val="1835618178"/>
    <w:placeholder>
    <w:docPart w:val="E7CBB9FF39374D7FB6C3C25547470DE6"/>
    </w:placeholder>
    <w:showingPlcHdr/>
    <w:text/>
    </w:sdtPr>
    <w:sdtContent>
    <w:p w:rsidR="0069030A" w:rsidRDefault="0069030A" w:rsidP="0069030A">
    <w:r w:rsidRPr="000A5EE9">
    <w:rPr>
    <w:rStyle w:val="PlaceholderText"/>
    </w:rPr>
    <w:t>Click here to enter text.</w:t>
    </w:r>
    </w:p>
    </w:sdtContent>
    </w:sdt>
    <w:p w:rsidR="003100C6" w:rsidRDefault="003100C6" w:rsidP="0069030A"/>
    <w:sdt>
    <w:sdtPr>
    <w:alias w:val="Earth"/>
    <w:tag w:val="Earth"/>
    <w:id w:val="178341326"/>
    <w:lock w:val="sdtContentLocked"/>
    <w:placeholder>
    <w:docPart w:val="D19A3040372E4220B01B643E2926FB99"/>
    </w:placeholder>
    <w:showingPlcHdr/>
    <w:text/>
    </w:sdtPr>
    <w:sdtContent>
    <w:p w:rsidR="003100C6" w:rsidRDefault="003100C6" w:rsidP="0069030A">
    <w:r w:rsidRPr="000A5EE9">
    <w:rPr>
    <w:rStyle w:val="PlaceholderText"/>
    </w:rPr>
    <w:t>Click here to enter text.</w:t>
    </w:r>
    </w:p>
    </w:sdtContent>
    </w:sdt>
    <w:sectPr w:rsidR="003100C6" w:rsidSect="009551F5">
    <w:pgSz w:w="12240" w:h="15840"/>
    <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="708" w:footer="708" w:gutter="0"/>
    <w:cols w:space="708"/>
    <w:docGrid w:linePitch="360"/>
    </w:sectPr>
    </w:body>
    </w:document>

    If you run this code you wont get first std as it is in paragraph.
    Is there a way i can get the list with all the cotentcontrols i.e stdblock no matter where it is in document?

    List<SdtBlock> sdtList = mainPart.Document.Descendants<SdtBlock>().Where(
    s => sourceFile.Contains(s.SdtProperties.GetFirstChild<Alias>().Val.Value)).ToList();

    Once i get the std block i will loop through it and insert html using altchunk.

    Can i insert altchunk anywhere in the document or it should always be under body tag?

    foreach (SdtBlock sdt in sdtList)
    {
    OpenXmlElement parent = sdt.Parent;
    parent.InsertAfter(altChunk, sdt);
    sdt.Remove();
    }
View as RSS news feed in XML