Building blocks and content controls are extremely flexible. You can create building blocks that contain content controls, or you can create content controls that use building blocks to present rich content selections to the user. In this video, you learn how to programmatically create a content control, and then how to programmatically add that content control to an entry in a building block gallery.
The following example inserts a content control into the active document, and then adds the content control to the collection of building blocks in the template attached to the active document.
private void InsertContentControlIntoBuildingBlock()
{
//Variable for the new content control.
Word.ContentControl objCC;
objCC = Application.ActiveDocument.
ContentControls.Add(Word
.WdContentControlType
.wdContentControlComboBox,
ref missing);
objCC.DropdownListEntries
.Add("Outstanding", "Outstanding", 1);
objCC.DropdownListEntries
.Add("Good", "Good", 2);
objCC.DropdownListEntries
.Add("Fair", "Fair", 3);
//Variables for the building block.
Word.Template objTemplate;
Word.BuildingBlock objBB;
Word.Range objRange;
objTemplate = (Word.Template)Application
.ActiveDocument.get_AttachedTemplate();
objRange = Application.ActiveDocument
.Paragraphs[1].Range;
objBB = objTemplate.BuildingBlockEntries
.Add("OGF Rating Scale",
Word.WdBuildingBlockTypes.wdTypeCustom1,
"Building Blocks", objRange, ref missing,
Word.WdDocPartInsertOptions
.wdInsertParagraph);
}