C# Word Automation - How to read checkbox values? RRS feed

  • Question

  • I am trying to write C# code to do word automation on filled out form.  This form uses Checkbox content controls (found in Word 2010/2013).  Can someone point me to some sample code on how I can iterate through each Checkbox control on the form to check the value of whether or not it is checked?   I am using Visual Studio 2008, if that matters.  Thanks!

    Tuesday, December 2, 2014 10:28 PM


  • Hi Scotty Lee,

    Thanks for posting on MSDN forum.

    Based on the description, you want to get or set the checkbox content control. Here is a sample to insert the checkbox content control into document and set its value for your reference:

       string fileName = @"C:\Users\UserName\Desktop\test.docx";
                            Word.Application word = new Word.Application();
                word.Visible = true;
                Word.Document doc = word.Documents.Open(fileName);
                Word.ContentControl cb = word.Selection.Range.ContentControls.Add(Word.WdContentControlType.wdContentControlCheckBox);
                word.ActiveDocument.Content.ContentControls[cb.ID].Checked = true;

    You can get more detail about content control from link below:
    ContentControl Object

    Regards & Fei

    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.

    Thursday, December 4, 2014 1:48 AM