FieldGreetingLine Class

Implements the GREETINGLINE field.
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsField
    Aspose.Words.FieldsFieldGreetingLine

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class FieldGreetingLine : Field

The FieldGreetingLine type exposes the following members.

Constructors
  NameDescription
Public methodFieldGreetingLine
Initializes a new instance of the FieldGreetingLine class
Properties
  NameDescription
Public propertyCode exampleAlternateText
Gets or sets the text to include in the field if the name is blank.
Public propertyCode exampleDisplayResult
Gets the text that represents the displayed field result.
(Inherited from Field.)
Public propertyCode exampleEnd
Gets the node that represents the field end.
(Inherited from Field.)
Public propertyCode exampleFormat
Gets a FieldFormat object that provides typed access to field's formatting.
(Inherited from Field.)
Public propertyCode exampleIsDirty
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field.)
Public propertyCode exampleIsLocked
Gets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field.)
Public propertyCode exampleLanguageId
Gets or sets the language id used to format the name.
Public propertyCode exampleLocaleId
Gets or sets the LCID of the field.
(Inherited from Field.)
Public propertyCode exampleNameFormat
Gets or sets the format of the name included in the field.
Public propertyCode exampleResult
Gets or sets text that is between the field separator and field end.
(Inherited from Field.)
Public propertyCode exampleSeparator
Gets the node that represents the field separator. Can be null.
(Inherited from Field.)
Public propertyCode exampleStart
Gets the node that represents the start of the field.
(Inherited from Field.)
Public propertyCode exampleType
Gets the Microsoft Word field type.
(Inherited from Field.)
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetFieldCode
Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
(Inherited from Field.)
Public methodCode exampleGetFieldCode(Boolean)
Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field.)
Public methodCode exampleGetFieldNames
Returns a collection of mail merge field names used by the field.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleRemove
Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null.
(Inherited from Field.)
Public methodToString (Inherited from Object.)
Public methodCode exampleUnlink
Performs the field unlink.
(Inherited from Field.)
Public methodCode exampleUpdate
Performs the field update. Throws if the field is being updated already.
(Inherited from Field.)
Public methodCode exampleUpdate(Boolean)
Performs a field update. Throws if the field is being updated already.
(Inherited from Field.)
Remarks
Inserts a mail merge greeting line.
Examples
Shows how to insert a GREETINGLINE field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a custom greeting field with document builder, and also some content
FieldGreetingLine fieldGreetingLine = (FieldGreetingLine)builder.InsertField(FieldType.FieldGreetingLine, true);
builder.Writeln("\n\n\tThis is your custom greeting, created programmatically using Aspose Words!");

// This array contains strings that correspond to column names in the data table that we will mail merge into our document
Assert.AreEqual(0, fieldGreetingLine.GetFieldNames().Length);

// To populate that array, we need to specify a format for our greeting line
fieldGreetingLine.NameFormat = "<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> ";

// In this case, our greeting line's field names array now has "Courtesy Title" and "Last Name"
Assert.AreEqual(2, fieldGreetingLine.GetFieldNames().Length);

// This string will cover any cases where the data in the data table is incorrect by substituting the malformed name with a string
fieldGreetingLine.AlternateText = "Sir or Madam";

// We can set the language ID here too
fieldGreetingLine.LanguageId = "1033";

Assert.AreEqual(" GREETINGLINE  \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033", fieldGreetingLine.GetFieldCode());

// Create a source table for our mail merge that has columns that our greeting line will look for
DataTable table = new DataTable("Employees");
table.Columns.Add("Courtesy Title");
table.Columns.Add("First Name");
table.Columns.Add("Last Name");
table.Rows.Add("Mr.", "John", "Doe");
table.Rows.Add("Mrs.", "Jane", "Cardholder");
// This row has an invalid value in the Courtesy Title column, so our greeting will default to the alternate text
table.Rows.Add("", "No", "Name");

doc.MailMerge.Execute(table);

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.GREETINGLINE.docx");
See Also