Reputation: 121
I'm having an issue with the way a DisplayName
is shown when getting the name of a computer user. Currently I use
public static string fullName = UserPrincipal.Current.DisplayName;
which returns "LastName, FirstName (Department)".
I need to have them displayed in the format of "FirstName LastName".
Is there a recommended way to do this?
Upvotes: 0
Views: 364
Reputation: 8725
Starting in Microsoft.NET 3.0, the UserPrincipal
class exposes the parts of the name (as documented here):
using System.DirectoryServices.AccountManagement;
/* ... */
var principal = UserPrincipal.Current;
var firstname = principal.GivenName;
var middlename = principal.MiddleName;
var lastname = principal.Surname;
var customcomposite = $"{firstname} {lastname}".TrimStart();
Upvotes: 2