In C # how to set the active field of the "office" directive so that I can show the location of our users in Outlook

In C # I am trying to set an office field

alt text

When I do this:

ADEntry.Properties ["office"]. Add ("Alaska");

It says that the office does not exist.

Can someone tell me where to get this property?

Thank,

Cal -

+3
source share
2 answers

Check out Richard Muller's website - he has tons of Excel help sheets about which property in the AD UI is mapped to which main property of AD is on DirectoryEntry.

"" , physicalDeliveryOfficeName DirectoryEntry .Properties....

+2

.

string Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(System.Security.Principal.WindowsIdentity.GetCurrent().Name.IndexOf("\\") + 1);

 string office = string.Empty;

    using (var context = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["DOMAIN"].ToString()))
    {
        using (var userPrincipal = new UserPrincipal(context))
        {
            userPrincipal.SamAccountName = Username;

            using (PrincipalSearcher search = new PrincipalSearcher(userPrincipal))
            {
                UserPrincipal result = (UserPrincipal)search.FindOne();

                DirectoryEntry directoryEntry = result.GetUnderlyingObject() as DirectoryEntry;

                if (directoryEntry.Properties["physicalDeliveryOfficeName"].Count > 0
                        && directoryEntry.Properties["physicalDeliveryOfficeName"][0] != null
                        && !string.IsNullOrWhiteSpace(directoryEntry.Properties["physicalDeliveryOfficeName"][0].ToString()))
                {
                    office = directoryEntry.Properties["physicalDeliveryOfficeName"][0].ToString();
                }
            }
        }
    }
+3

Source: https://habr.com/ru/post/1770754/


All Articles