FieldGreetingLineGetFieldNames Method

Returns a collection of mail merge field names used by the field.

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public string[] GetFieldNames()

Return Value

Type: String

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 along with some content
FieldGreetingLine field = (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, field.GetFieldNames().Length);

// To populate that array, we need to specify a format for our greeting line
field.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, field.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
field.AlternateText = "Sir or Madam";

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

Assert.AreEqual(" GREETINGLINE  \\f \"<< _BEFORE_ Dear >><< _TITLE0_ >><< _LAST0_ >><< _AFTER_ ,>> \" \\e \"Sir or Madam\" \\l 1033", 
    field.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