HotDocs.AnswerCollection Object

This object represents sets of answers, which most frequently come from HotDocs answer files saved on disk. However, this is not the only way answers are stored—an AnswerCollection object can represent answers that were input from an interview, retrieved from a database, or imported from any other source you tell your program to use.

AnswerCollection objects are also used elsewhere in the HotDocs API to specify a set of answers to use in an assembly, and when responding to events fired from the Application and Assembly objects.

General Information

ProgID: HotDocs.AnswerCollection.11.0
HotDocs.AnswerCollection (version-independent)
CLSID: {F6B3FF63-D730-4DCE-802D-0FAED25E7B72}

The following table shows the name and IID for each interface, as well as the version of HotDocs in which it was introduced. The primary interface and the main public interface exposed by this object is _AnswerCollection2.

Name IID Added in
_AnswerCollection {3E419C82-EED2-4FD4-BD37-C4BC9A9FEFB1} Added in HotDocs 6.0
_AnswerCollection2 {A9BED2DE-BAE7-4BF9-93D4-E944E81A6F8E} Added in HotDocs 2005 SP2

Methods

Method Description
Add This method adds a new answer to the AnswerCollection. This answer must have already been initialized using the Create method.
Close If an AnswerCollection is backed by an answer file on disk, the answer file is kept open while the AnswerCollection object is in use. This method closes the answer file on disk.
Create This method initializes the AnswerCollection object. You must call this method before using a new AnswerCollection object.
Item This method retrieves an Answer object from the AnswerCollection.
Overlay This method overlays the filename answer file on top of the existing answer set.
Save This method saves the AnswerCollection to a HotDocs answer file. The file type (.ANS or .ANX) is determined by the FileFormat property.
UploadAnswerCollection This method uploads the AnswerCollection to the specified location (url).

Properties

Property Description
Application [Read-only] This property returns a reference to the Application object.
Count [Read-only] This property returns the number of Answer objects in the AnswerCollection.
DefaultAnswerFile [Read/Write] This property returns the default answer file used by the AnswerCollection. Using a default answer file is similar to using an overlay answer file except that the answers are underlayed into the answer set. (For details, see Create a Default Answer File.)
Description [Read/Write] This property sets or returns the description of the AnswerCollection.
FileFormat [Read/Write] This property determines the answer file format.
FileName [Read-only] This property returns the file name of the answer file represented by the AnswerCollection object. To specify the file path for the answer file, pass the file path and name to either the Create or Save method.
Modified [Read-only] This Boolean property indicates if an AnswerCollection has been modified or not.
Title [Read/Write] This property sets or returns the title of the AnswerCollection.
XML [Read-only] This property returns the AnswerCollection as an XML string.

 

Example

The following Visual C# example opens an answer file and displays each answer it contains:

public class ExampleCode
{
    static string ansName;
    static string ansType;
     
    static void Main() 
    {
        HotDocs.AnswerCollection ac = new HotDocs.AnswerCollection();
        ac.Create(@"C:\Documents\HotDocs\Answers\AnswerFile.anx");
         
        Console.WriteLine("Variable\tAnswer\tType");
         
        foreach (HotDocs.Answer ans in ac)
        {
            ansName = ans.Name;
            ansType = getType(ans.Type);
            ans.OnValueFoundEvent += new HotDocs._AnswerEvents_OnValueFoundEventEventHandler(ans_OnValueFoundEvent); 
            ans.IterateValues(); 
        }
        Console.ReadKey();
         
        ac.Close();
    }
     
    static void ans_OnValueFoundEvent(object Value, int repeat1, int repeat2, int repeat3, int repeat4)
    {
        string index = ""; 
        string ansValue = ""; 
        if (repeat1 > -1) index = "[" + (repeat1 + 1).ToString() + "] ";
        //Check to see if the value is an array (multiple-select Multiple Choice variable)
        if (Value.GetType() == typeof(System.Object[]))
            foreach (string s in (System.Object[])Value)
            {
                ansValue += s + "; ";
            }
            else
                ansValue = Value.ToString();
              
            Console.WriteLine(index + ansName + "\t" + ansValue + "\t" + ansType);
    }
     
    static string getType(HotDocs.HDVARTYPE type)
    {
        switch (type)
        {
            case HotDocs.HDVARTYPE.HD_DATETYPE: 
                return "Date"; 
            case HotDocs.HDVARTYPE.HD_MULTCHOICETYPE: 
                return "Multiple Choice";
            case HotDocs.HDVARTYPE.HD_NUMBERTYPE: 
                return "Number"; 
            case HotDocs.HDVARTYPE.HD_TEXTTYPE: 
                return "Text"; 
            case HotDocs.HDVARTYPE.HD_TRUEFALSETYPE: 
                return "True/False"; 
            default:
                return type.ToString(); 
        }
    }
}