May 5th, 2013, 10:58 PM
C# check merge field check box in a word document
Using Visual Studio 2012 with Office 2010.
Just wondering how to check a check box content control on a word document, i have my C# Window Forms application filling in Merge Fields with data obtained from the forms such as textBoxes and comboBoxes. Though i was wondering how to check a text box from with in C#?
I have been trying to find this for awhile now, and have resulted in actually asking the question here.
The code below is how i connect to my word document and fill out the Merge Field on that document.
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
oWord.Visible = true;
FileStream file = new FileStream("pathName.txt", FileMode.Open, FileAccess.Read);
StreamReader Reader = new StreamReader(file);
PathName = Reader.ReadLine();
Object oTemplatePath = PathName;
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Word.Field myMergeField in oWordDoc.Fields)
Word.Range rngFieldCode = myMergeField.Code;
String fieldText = rngFieldCode.Text;
if (fieldText.StartsWith(" MERGEFIELD"))
Int32 endMerge = fieldText.IndexOf("\\");
Int32 fieldNameLength = fieldText.Length - endMerge;
String fieldName = fieldText.Substring(11, endMerge - 11);
fieldName = fieldName.Trim();
if (fieldName == "Name")
if (fieldName == "Name2")
if (fieldName == "LastName1")
Any help would be appreciated.
Last edited by Dredious; May 7th, 2013 at 12:20 AM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!