Fields in ASP.NET Core DOCX Editor

27 Aug 20261 minute to read

ASP.NET Core DOCX Editor (Document Editor) has preservation support for all types of fields in an existing word document without any data loss.

Adding fields

You can add a field to the document by using insertField method in Editor module.

var fieldCode = 'MERGEFIELD  First Name  \\* MERGEFORMAT ';
var fieldResult = '«First Name»';
documenteditor.editor.insertField(fieldCode, fieldResult);

DOCX Editor does not validate or process the field code or field result. It simply inserts the field with specified field information.

Update fields

DOCX Editor provides support for updating bookmark cross reference field.

//Update all the bookmark cross reference field in the document.
documenteditor.updateFields();

Bookmark cross reference fields can be updated through UI by using update fields option in Toolbar.

Update bookmark cross reference field.

The following type of fields are automatically updated in DOCX Editor.

  • NUMPAGES
  • SECTION
  • PAGE

Get field info

You can get field code and field result of the current selected field by using getFieldInfo method in the Selection module.

//Gets the field information of the selected field.
var fieldInfo = documenteditor.selection.getFieldInfo();

For nested fields, this method returns combined field code and result.

Set field info

You can modify the field code and field result of the current selected field by using setFieldInfo method in the Editor module.

//Gets the field information for the selected field.
var fieldInfo = documenteditor.selection.getFieldInfo();

//Modify field code
fieldInfo.code = 'MERGEFIELD  First Name  \\* MERGEFORMAT ';

//Modify field result
fieldInfo.result = '«First Name»';

//Modify field code and result of the current selected field.
documenteditor.editor.setFieldInfo(fieldInfo);

For nested field, entire field gets replaced completely with the specified field information.

See Also

Mail merge using DocIO
Mail merge demo