User Information

User Information

This guide shows how to set the current-user identity that Aspose.Words FOSS for .NET reports through user-related document fields.

UserInformation represents the identity Aspose.Words FOSS for .NET uses when evaluating fields that report “the current user” — Name, Initials, and Address. It is attached to a document’s field-evaluation settings through FieldOptions.CurrentUser, and a process-wide fallback is available through UserInformation.DefaultUser.


Setting the Current User

Document.FieldOptions (a FieldOptions instance) exposes CurrentUser, a UserInformation object. Set its Name, Initials, and Address properties before updating user-information fields so the values they report match the identity your application wants recorded. UserInformation.DefaultUser provides a static, process-wide UserInformation instance to fall back on when a document’s FieldOptions.CurrentUser has not been set explicitly.


User-Information Fields

Three Field subclasses read the current user’s identity into the document body: FieldUserName (the USERNAME field, with a UserName property), FieldUserAddress (the USERADDRESS field, with a UserAddress property), and FieldUserInitials (the USERINITIALS field, with a UserInitials property). Like other fields, they share the base Field lifecycle — GetFieldCode(), Result, Update(), Unlink(), Remove() — and can be inserted with DocumentBuilder.InsertField(fieldCode) or InsertField(fieldType, updateField) using FieldType.FieldUserName, FieldType.FieldUserAddress, or FieldType.FieldUserInitials.


Tips and Best Practices

  • Set FieldOptions.CurrentUser before calling Update() on a FieldUserName, FieldUserAddress, or FieldUserInitials field, or before Document.UpdateFields() — otherwise the fields resolve against whatever UserInformation is currently in effect.
  • UserInformation.DefaultUser is a convenient shared default when the same identity applies across every document your application processes; set FieldOptions.CurrentUser per-document when different documents need different authors.
  • Populate all three of Name, Initials, and Address together if your templates use more than one of FieldUserName, FieldUserAddress, and FieldUserInitials — leaving one blank produces an empty field result rather than an error.

Common Issues

IssueCauseFix
FieldUserName result is empty after Update()UserInformation.Name was never set on the active UserInformationSet FieldOptions.CurrentUser.Name (or UserInformation.DefaultUser.Name) before updating the field
User-information fields show the wrong author across documentsUserInformation.DefaultUser is shared process-wideSet Document.FieldOptions.CurrentUser per document instead of relying on the default

FAQ

What is the difference between FieldOptions.CurrentUser and UserInformation.DefaultUser?

FieldOptions.CurrentUser is per-document — set it on a specific Document’s FieldOptions to control that document’s user-information fields. UserInformation.DefaultUser is a static, process-wide fallback.

Which fields does UserInformation affect?

FieldUserName (USERNAME), FieldUserAddress (USERADDRESS), and FieldUserInitials (USERINITIALS) — each reads the corresponding Name, Address, or Initials property from the active UserInformation.

Do I need to call Update() after changing UserInformation?

Yes — changing Name, Initials, or Address does not retroactively update fields already evaluated in the document; call Update() on the specific field or Document.UpdateFields().


API Reference Summary

Class / PropertyDescription
UserInformationName, Initials, Address; DefaultUser static fallback instance
FieldOptions.CurrentUserPer-document UserInformation used when evaluating user-information fields
FieldUserName / FieldUserAddress / FieldUserInitialsUSERNAME, USERADDRESS, USERINITIALS fields

See Also