locked
Update LDAP entries RRS feed

  • Question

  • User235720903 posted

    Hello,

     I need to find a user in AD with only is email, then I need to update entrie like his phoneNumber, fax, mobile, ...

    Is it possible ? And how to do that ?

     Thank you very much for your answer

    Friday, March 6, 2009 3:37 AM

Answers

  • User-845805365 posted

     yeah it is possible to find a user with email id.

    Code snippet

    public static DirectoryEntry GetDirectoryEntry(string DomainReference)
        {       
            string ADFullPath ="LDAP://Domain.com";       
            DirectoryEntry de = new DirectoryEntry(ADFullPath + DomainReference,your Username, your password, AuthenticationTypes.Secure);
            return de;
        }

        private static string GetLDAPDomain()
        {
            StringBuilder LDAPDomain = new StringBuilder();
            string[] LDAPDC = "domainName.com".Split('.');
            for (int i = 0; i < LDAPDC.GetUpperBound(0) + 1; i++)
            {
                LDAPDomain.Append("DC=" + LDAPDC[i]);
                if (i < LDAPDC.GetUpperBound(0))
                {
                    LDAPDomain.Append(",");
                }
            }
            return LDAPDomain.ToString();
        }

     

     put this in button click or page load or something...

    string mailId="Your mail id which you ar eusing for search";

    DirectoryEntry entry = GetDirectoryEntry("/" + GetLDAPDomain());
    DirectorySearcher search = new DirectorySearcher(entry);
    search.Filter = "(mail=" + mailID + ")";
    search.PropertiesToLoad.Add("name");// load the properties one by one which you wanna access
    SearchResult result = search.FindOne();

    in the search result you will have all the properites loaded from the AD.

     

    please go through this link to get more detaisl about AD querrying...

    http://www.dotnetactivedirectory.com/Accessing%20LDAP%20Active%20Directory%20from%20C%20Sharp%20or%20VB%20.NET%20Code.html#%20or%20VB%20.NET%20Code.html

    http://www.willasrari.com/blog/query-active-directory-users-using-c/000133.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2009 5:10 AM

All replies

  • User-845805365 posted

     yeah it is possible to find a user with email id.

    Code snippet

    public static DirectoryEntry GetDirectoryEntry(string DomainReference)
        {       
            string ADFullPath ="LDAP://Domain.com";       
            DirectoryEntry de = new DirectoryEntry(ADFullPath + DomainReference,your Username, your password, AuthenticationTypes.Secure);
            return de;
        }

        private static string GetLDAPDomain()
        {
            StringBuilder LDAPDomain = new StringBuilder();
            string[] LDAPDC = "domainName.com".Split('.');
            for (int i = 0; i < LDAPDC.GetUpperBound(0) + 1; i++)
            {
                LDAPDomain.Append("DC=" + LDAPDC[i]);
                if (i < LDAPDC.GetUpperBound(0))
                {
                    LDAPDomain.Append(",");
                }
            }
            return LDAPDomain.ToString();
        }

     

     put this in button click or page load or something...

    string mailId="Your mail id which you ar eusing for search";

    DirectoryEntry entry = GetDirectoryEntry("/" + GetLDAPDomain());
    DirectorySearcher search = new DirectorySearcher(entry);
    search.Filter = "(mail=" + mailID + ")";
    search.PropertiesToLoad.Add("name");// load the properties one by one which you wanna access
    SearchResult result = search.FindOne();

    in the search result you will have all the properites loaded from the AD.

     

    please go through this link to get more detaisl about AD querrying...

    http://www.dotnetactivedirectory.com/Accessing%20LDAP%20Active%20Directory%20from%20C%20Sharp%20or%20VB%20.NET%20Code.html#%20or%20VB%20.NET%20Code.html

    http://www.willasrari.com/blog/query-active-directory-users-using-c/000133.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2009 5:10 AM
  • User235720903 posted

    Thank you for your answer, fewmore questions:

    My LDAP server is a Domino LDAP server, does it works too ?

    My domain name is like:

    dominoLDAP.itc.de.org

    How do I define the domain reference ?

    Thank you in advance

     

    Tuesday, December 8, 2009 4:17 AM