ComponentCollection.CreateComponent Method

This method allows you to create virtually any type of HotDocs variable or component in a component file. Once the component is created, its properties can be set and modified using the ComponentProperties object. If the component already exists in the component collection, this method does nothing.

This method was introduced with the release of HotDocs 2006.

Syntax

void CreateComponent ( string componentName, HotDocs.HDVARTYPE componentType )

Parameters Description
componentName The name of the component to create.
componentType The type of the new component.

Example

The following Visual C# example creates a new component and then displays the names of each property in its ComponentProperties collection.

public class ExampleCode
{
    static void Main()
    {
        HotDocs.ComponentCollection ccl = new HotDocs.ComponentCollection();
         
        ccl.OpenForEdit(@"C:\Documents\HotDocs\Templates\demoempl.cmp"); 
         
        HotDocs.HDVARTYPE varType = HotDocs.HDVARTYPE.HD_TEXTTYPE;
        HotDocs.Component comp;
         
        ccl.CreateComponent("Attorney Name", varType);
         
        comp = ccl.Item("Attorney Name", ref varType) as HotDocs.Component;
         
        for (int i = 0; i < comp.Properties.Count; i++)
            Console.WriteLine(comp.Properties.Item(i).Name);
         
        Console.ReadKey();
    }
}