0

I've seen a similar question asked but cannot seem to solve my issue ( not actually sure if what I'm trying to achieve is possible! )

Context: I'm creating a Windows Form C# application that allows for users to select and send a HTML template to a customer through the SendGrid API (Irrelevant)

When the User sends an Email, I am logging their detail on a CSV with their UserName which is B12345 for example, but each system knows their name (As it's the title of their Personal Folder), but when I simply get the path of the 'Special Folder' I get C:\Users\B12345.

Where can I access the logged on user alias? i.e. their full name?

DeclanPossnett
  • 376
  • 1
  • 5
  • 13
  • wait, you save user B12345 details in a csv - in a folder with their name (i.e C:\Users\B12345)? what are you trying to load exactly? – gilmishal Sep 05 '16 at 11:21
  • Note that the *display name* of a user's profile (home) directory is not necessarily the same as the actual filesystem of their home directory. The `desktop.ini` file plays tricks on everyone. – Dai Sep 05 '16 at 11:22
  • gilmishal - I am not saving there, sorry. Each user will write to a CSV saved on the server, that's working fine. My question is simply to try and get the Logged in User's Full Name, from their UserName, which happens to be always formatted similar to B12345. If I log in as B12345, then my personal folder would be "Declan Possnett" for example. – DeclanPossnett Sep 05 '16 at 11:26
  • Dai - Any ideas on a solution, or anything I should look at trying? – DeclanPossnett Sep 05 '16 at 11:29
  • Does this answer your question? [Get Windows User Display Name](https://stackoverflow.com/questions/22187761/get-windows-user-display-name) – Adrian Mole Feb 28 '21 at 18:07

1 Answers1

1

There is a very similar question here: Get Windows User Display Name

Basically, from what I understand of your question you are after the display name of a user as opposed to their actual user name. As such you probably want to use the DisplayName property of UserPrincipal.

System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName

As the other question states, you need a reference to :

System.DirectoryServices.AccountManagement.dll

Community
  • 1
  • 1
Pheonyx
  • 851
  • 6
  • 15