Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing the initials field using the DirectoryServices.AccountManagement

I'm new to accessing Active Directory and I was advised to use System.DirectoryServices.AccountManagement but I can't find the initials variable any help ?

like image 646
Shehab Fawzy Avatar asked Dec 27 '22 09:12

Shehab Fawzy


1 Answers

You can do one of those things:

1) you can extend the normal UserPrincipal class to include additional items that you frequently need. This would be the cleanest solution, really. See the MSDN docs on extending the user principal, or answer to this SO question for an example of how to extend the UserPrincipal class with additional properties

2) You could just "reach down" into the depths of your underlying DirectoryEntry and grab the data from there:

    DirectoryEntry de = YourUserPrincipal.GetUnderlyingObject() as DirectoryEntry;

    if(de != null)
    {  
       var initials = de.Properties["initials"];

       if(initials != null && initials.Count > 0)
       {
          string theInitials = de.Properties["initials"][0].ToString();
       }
    }
like image 140
marc_s Avatar answered Feb 13 '23 05:02

marc_s