Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 16, 2012 11:43 AM by george_d37
Nov 13, 2012 12:13 PM|LINK
I have several contentcontrols in a word document that I am trying to fill using c#. My code works fine when the contentcontrol in the word document is empty. However, when I enter text in the contentcontrol, save, then try to edit or update this text using
c#, the update does not happen! Here is my update code:
control.SetPlaceholderText(null, null, newText);
Is there a way to change the text in a contentcontrol that already has text in it? How?
Any help much appreciated.
Nov 15, 2012 08:40 AM|LINK
This is because you are changing the placeholder text and not the text of the content control. Placeholder text is a text that only shows up when the content of a content control is empty (e.g. "Insert text here").
Instead, do the following:
control.Range.Text = newText;
Just to alert you: Using Office application automation using COM in ASP.NET applications is
not recommended. For your scenario you should consider either creating an
Open XML solution or getting a 3rd party solution.
Nov 16, 2012 11:43 AM|LINK
Thanks for the help.
In my case, I have users who create a word template with specific fields (contentcontrols) to be populated from the database.
I am creating a button in the ribbon that once clicked, opens a textbox in which the user inserts the name of an employee and clicks ok. Some code will then execute to fetch the data related to this employee and populate the word template with these data.
I have looked at using xml but it appears that xml stopped working due to court ruling if im not mistaken. Please guide me as to whether what I am doing is the best option or if there is a better way to doing this.