Search code examples
c#vstocontentcontrolautofillword-2010

Set text in an existing contentcontrol in word 2010 with c# and VSTO


I've been looking and googling around for 4h to find a solution for my problem.

I'm trying to set the text of an defined rich text content control. For test purposes i defined just one content control (rich text) in the document where i would like to change the text.

var docx = Application.Documents.Open(@"D:\BaseDocs\Test.docx");
var all = GetAllContentControls(docx); // Returns all content controls in active document
var one = all.First(); // Select first one --> works
((RichTextContentControl)one).Text = "Test" //Trying to set text --> invalid cast exception

I can't set the value of this predefined content control. Any help is really appreciated.


Solution

  • Solved. I took bookmarks to solve this problem. Thank you all for helping me out.