HotDocs.Server.AnswerCollection Class

An AnswerCollection is a group of Answer objects, which HotDocs Server uses when it assembles a document. Each Answer in the collection represents a different HotDocs variable, each of which may contain one or more values. For example, the Answer for a variable in a dialog that is repeated five times would contain five values. During document assembly, HotDocs replaces variable fields in the template with corresponding answers from the AnswerCollection.

AnswerCollection objects may be saved on disk as HotDocs answer files; likewise, you can open an existing answer file and read its answers to populate a new AnswerCollection.

Namespace: HotDocs.Server
Assembly: HotDocs.Server in HotDocs.Server.dll

This class implements the following interfaces:

  • IDisposable: The class can be disposed.

  • IList: The class is a list of Answer objects.

Methods

Method Description
AnswerCollection (Constructor) This constructor initializes a new instance of the AnswerCollection class.
Add   This method adds a new Answer to the AnswerCollection.
AddAnswer This method creates a new Answer object and adds it to the AnswerCollection. If the answer already exists in the answer collection, its value will be replaced with the value in the value parameter.
Clear This method removes all answers from the AnswerCollection.
Contains This method determines whether or not the AnswerCollection contains a specific value.
CopyTo This method copies the elements of the AnswerCollection to an Array, starting at a particular index.
Dispose This method is an implementation of the IDisposable.Dispose method that releases unmanaged resources held by an instance of the AnswerCollection class.
GetEnumerator This method returns an enumerator that iterates through the AnswerCollection.
GetRptCount This method returns the number of repetitions of an answer at a specific index.
IndexOf This method determines the index of a specific item in the AnswerCollection.
Insert Inherited from the IList interface, but not implemented.

This method is inherited from the IList interface, but it is not implemented in the AnswerCollection class. It will throw a NotImplementedException if called.

Open This method opens an existing answer file and populates the AnswerCollection. If the answer file does not exist, however, this method will return an error.
OverlayAnswerFile This method specifies an answer file to overlay on top of the answers in the AnswerCollection.
OverlayXMLAnswers This method specifies an XML answer string to overlay on top of the answers in the AnswerCollection.
Remove This method removes the first occurrence of a specific object from the AnswerCollection.
RemoveAt This method removes the AnswerCollection item at the specified index.
Save This method saves the AnswerCollection to a file.
ValidateXMLAnswerFile This method determines whether or not the specified XML answer file is valid.
ValidateXMLAnswerSet This method determines whether or not the specified XML answer string is valid (conforms to the HotDocs Server answer DTD).

Properties

Property Description
Count [Read-only] This property returns the number of Answer objects in the AnswerCollection.
FileFormat [Read/Write] This property sets or returns the answer file format value. The value comes from the ansFileformat enumeration.
FileName [Read-only] This property specifies the file name of the AnswerCollection.
Item [Read-only] This property gets the specified answer in the collection.
XmlAnswers [Read/Write] This property represents the answers in the AnswerCollection as an XML string.

Example

The following Visual C# example gets the answers from the browser interview, puts them into an AnswerCollection, then writes all the answers back out in the response HTML.

//Put the answers from the interview into the answer collection.
_session.CurrentAssembly.AnswerCollection.XmlAnswers = HotDocs.Server.InterviewResponse.GetInterviewAnswers(Request);
 
foreach(HotDocs.Server.Answer ans in _session.CurrentAssembly.AnswerCollection) // every answer in the answer collection
{
    System.Text.StringBuilder answerTxt = new System.Text.StringBuilder(); // to hold the values we read out of the answerset
    answerTxt.AppendFormat("{0} : {1}<br>",ans.AnswerTypeText,ans.Name); // get the answer type and name
    foreach(HotDocs.Server.Value val in ans) // every value in the answer
    {
        object [] parms = new object[5];
        // get the repeat indices
        parms[0] = val.RepeatIndex1.ToString();
        parms[1] = val.RepeatIndex2.ToString();
        parms[2] = val.RepeatIndex3.ToString();
        parms[3] = val.RepeatIndex4.ToString();
        // get the value
        parms[4] = val.value.ToString();
        answerTxt.AppendFormat(" {0},{1},{2},{3} : {4}<br>",parms);
        Response.Write answerTxt.ToString();
    }
}