Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I use this code for find users in AD

  SearchResultCollection results = null;
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                System.DirectoryServices.DirectoryEntry entry = new DirectoryEntry("LDAP://...");
                DirectorySearcher adSearcher = new DirectorySearcher(entry);
                adSearcher.SearchScope = SearchScope.Subtree;
               adSearcher.Filter = "(&(objectClass=user)(sAMAccountName=" + userName + "))";

                results = adSearcher.FindAll();
            });
        }
        catch (Exception e)
        {

        }

and add a Children

 using (DirectoryEntry ou = new DirectoryEntry("LDAP://Domainname"))
            {

                DirectoryEntry user = ou.Children.Add("CN=" + txtuser.Text, "user");
                int NORMAL_ACCOUNT = 0x200;
                int PWD_NOTREQD = 0x20;
                user.Properties["sAMAccountName"].Value = txtuser.Text;
                user.Properties["userAccountControl"].Value = NORMAL_ACCOUNT | PWD_NOTREQD;
                user.Properties["displayName"].Value = txtname.Text;
                user.Properties["mail"].Value=txtemail.TemplateControl;
                user.Properties["description"].Value = txtnote.Text;
                user.CommitChanges();
                user.Invoke("SetPassword", new object[] { txtpass.Text });
            }

How do modify active directory user properties?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Check this post for detailed examples on how active directory properties are retrieved and updated - http://www.ianatkinson.net/computing/adcsharp.htm

share|improve this answer
    
Thanks a lot :) –  ar.gorgin Apr 17 '12 at 3:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.