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.CurrentUserbefore callingUpdate()on aFieldUserName,FieldUserAddress, orFieldUserInitialsfield, or beforeDocument.UpdateFields()— otherwise the fields resolve against whateverUserInformationis currently in effect. UserInformation.DefaultUseris a convenient shared default when the same identity applies across every document your application processes; setFieldOptions.CurrentUserper-document when different documents need different authors.- Populate all three of
Name,Initials, andAddresstogether if your templates use more than one ofFieldUserName,FieldUserAddress, andFieldUserInitials— leaving one blank produces an empty field result rather than an error.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
FieldUserName result is empty after Update() | UserInformation.Name was never set on the active UserInformation | Set FieldOptions.CurrentUser.Name (or UserInformation.DefaultUser.Name) before updating the field |
| User-information fields show the wrong author across documents | UserInformation.DefaultUser is shared process-wide | Set 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 / Property | Description |
|---|---|
UserInformation | Name, Initials, Address; DefaultUser static fallback instance |
FieldOptions.CurrentUser | Per-document UserInformation used when evaluating user-information fields |
FieldUserName / FieldUserAddress / FieldUserInitials | USERNAME, USERADDRESS, USERINITIALS fields |