I am using this code to put content in a Field using Word Interop:
var wordApp = new Microsoft.Office.Interop.Word.Application();
var wordDoc = wordApp.Documents.Add(Path.GetFullPath("myTemplate.dotx"));
Field f = wordDoc.Fields[0];
f.Select();
wordApp.Selection.TypeText("some text");
but this works only once. If I run the f.Select() statement again, I get a COMException telling me the object is gone.
Is there a way to overwrite field content? Or do I have to work with being able to write a Field only once?
When you select the field, and then use
TypeText, that replaces the whole field with your input text. Instead, you should be using Field.Result property:Therefore, your code should be something like the following:
Hope that helps :)