none
Remove default text "Click here to enter text." from all content controls RRS feed

  • Question

  • Hi,

    Whenever I add a content control inside Word 2010 document I see a default text "Click here to enter text.". I don't want my end users to see such text in the document. Is there a way to remove of disable this feature in Word 2010.

    I am populating text into content controls in my document using OpenXml SDK. BUT wanted to know if there is a setting to disable this default text in content control. I can write code to remove this text through code but that's just a waste :(.  I have about 50 odd content controls in a document.

    Regards,

    Vijay

    Thursday, July 17, 2014 4:27 AM

Answers

  • Hi Vijay

    If you look at the WordOpenXML for an "empty" content control you should see something like this

    <w:placeholder>
    <w:docPart w:val="615C0E25A403493B9B67FE508CBDF358"/>
    </w:placeholder>
    <w:showingPlcHdr/>

    This is telling you that the text for the placeholder is found in the GALLERY ("glossaryDocument") of the document, the item with the GUID *and* that the currently visible text in the content control is being treated as a placeholder. See:

    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.showingplaceholder(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.docparts(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.docpart(v=office.14).aspxSo, you can control what is displayed as the placeholder in a DocPart. Here's an example of the underlying WordOpenXML

    <w:docParts><w:docPart><w:docPartPr><w:name w:val="615C0E25A403493B9B67FE508CBDF358"/>
    <w:category><w:name w:val="General"/><w:gallery w:val="placeholder"/></w:category>
    <w:types><w:type w:val="bbPlcHdr"/></w:types>
    <w:behaviors><w:behavior w:val="content"/></w:behaviors>
    <w:guid w:val="{4AAFF751-23B2-4C80-BE66-4D3015DB61BE}"/></w:docPartPr>
    <w:docPartBody><w:p w:rsidR="00000000" w:rsidRDefault="00DA013C" w:rsidP="00DA013C">
    <w:pPr><w:pStyle w:val="615C0E25A403493B9B67FE508CBDF358"/></w:pPr>
    <w:r w:rsidRPr="00FA5151"><w:rPr><w:rStyle w:val="PlaceholderText"/></w:rPr>
    <w:t>Click here to enter text.</w:t></w:r></w:p>
    </w:docPartBody></w:docPart></w:docParts>

    You could, for example, search descendants of DocPartBody with the text "Click here to enter text." and substitute your own value.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 18, 2014 5:47 PM
    Moderator
  • Hi Vijay,

    I'm afraid the default text is define by this content control, we can not set this property through OpenXML SDK. If you can find the source code of this content control, you can change this property and re-add into Word.

    Through Open XML SDK, what we can do is to loop all content controls in a document and change its text. Here is a sample for your reference:

    static void ChangeDefaultContent()
            {
                string documentPath = @"D:\Content Control.docx";
                using (WordprocessingDocument package = WordprocessingDocument.Open(documentPath, true))
                {
                    MainDocumentPart mainPart = package.MainDocumentPart;
                    Body body = package.MainDocumentPart.Document.Body;
                    foreach (SdtBlock scb in body.Descendants<SdtBlock>())
                    {
                        Run r = scb.GetFirstChild<SdtContentBlock>().GetFirstChild<Paragraph>().GetFirstChild<Run>();
                        Text t = r.GetFirstChild<Text>();
                        t.Text = "Test";
                    }
                }
            }

    In addition, there might be some content controls under paragraphs, so you may need to loop all paragraphs to find such content control and change its text.

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 18, 2014 3:03 AM
    Moderator

All replies

  • Hi Vijay,

    I'm afraid the default text is define by this content control, we can not set this property through OpenXML SDK. If you can find the source code of this content control, you can change this property and re-add into Word.

    Through Open XML SDK, what we can do is to loop all content controls in a document and change its text. Here is a sample for your reference:

    static void ChangeDefaultContent()
            {
                string documentPath = @"D:\Content Control.docx";
                using (WordprocessingDocument package = WordprocessingDocument.Open(documentPath, true))
                {
                    MainDocumentPart mainPart = package.MainDocumentPart;
                    Body body = package.MainDocumentPart.Document.Body;
                    foreach (SdtBlock scb in body.Descendants<SdtBlock>())
                    {
                        Run r = scb.GetFirstChild<SdtContentBlock>().GetFirstChild<Paragraph>().GetFirstChild<Run>();
                        Text t = r.GetFirstChild<Text>();
                        t.Text = "Test";
                    }
                }
            }

    In addition, there might be some content controls under paragraphs, so you may need to loop all paragraphs to find such content control and change its text.

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 18, 2014 3:03 AM
    Moderator
  • Hi Vijay

    If you look at the WordOpenXML for an "empty" content control you should see something like this

    <w:placeholder>
    <w:docPart w:val="615C0E25A403493B9B67FE508CBDF358"/>
    </w:placeholder>
    <w:showingPlcHdr/>

    This is telling you that the text for the placeholder is found in the GALLERY ("glossaryDocument") of the document, the item with the GUID *and* that the currently visible text in the content control is being treated as a placeholder. See:

    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.showingplaceholder(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.docparts(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.docpart(v=office.14).aspxSo, you can control what is displayed as the placeholder in a DocPart. Here's an example of the underlying WordOpenXML

    <w:docParts><w:docPart><w:docPartPr><w:name w:val="615C0E25A403493B9B67FE508CBDF358"/>
    <w:category><w:name w:val="General"/><w:gallery w:val="placeholder"/></w:category>
    <w:types><w:type w:val="bbPlcHdr"/></w:types>
    <w:behaviors><w:behavior w:val="content"/></w:behaviors>
    <w:guid w:val="{4AAFF751-23B2-4C80-BE66-4D3015DB61BE}"/></w:docPartPr>
    <w:docPartBody><w:p w:rsidR="00000000" w:rsidRDefault="00DA013C" w:rsidP="00DA013C">
    <w:pPr><w:pStyle w:val="615C0E25A403493B9B67FE508CBDF358"/></w:pPr>
    <w:r w:rsidRPr="00FA5151"><w:rPr><w:rStyle w:val="PlaceholderText"/></w:rPr>
    <w:t>Click here to enter text.</w:t></w:r></w:p>
    </w:docPartBody></w:docPart></w:docParts>

    You could, for example, search descendants of DocPartBody with the text "Click here to enter text." and substitute your own value.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 18, 2014 5:47 PM
    Moderator