Change data in AD RRS feed

  • Question

  • User1133938822 posted

    Hi to all,

    Is there possibility to create website with I will be able to change user information like email, address, phone number in ActiveDirectory ??

    Thanks in advance for answer

    Thursday, October 1, 2015 3:17 AM

All replies

  • User-271186128 posted

    Hi Kremius,

    From your description, it seems that you want to modify the object properties in an Active Directory Hierarchy. If that is the case, you can use the DirectoryEntry class to retrieve a node from an Active Directory hierarchy and modify its property content.

    You could refer to the following steps:

    1. Create an instance of the DirectoryEntry component, binding it to the known object in the active directory hierarchy with the object's path.
    2. Make the necessary changes to the object's properties by referring to it by name.
    3. Call the CommitChanges method save your modifications to the item in the directory.

    For more details, please refer to this article: https://msdn.microsoft.com/en-us/library/dx0d151f%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396

    Please Note: You must have administrator rights to a directory in order to modify any of its information.

    Besides, since this issue is related to the Active Directory, if you have any further question about Active Directory, I suggest you could post you problem to Active Directory forum: http://forums.asp.net/93.aspx/1?Active+Directory+and+LDAP

    Best regards,

    Thursday, October 1, 2015 10:23 PM
  • User1133938822 posted

    Could you make a 'sample' because I don't really know how to do it (let's say that I'm new in ASP NET) ;)

    Thanks in advance :)

    Friday, October 2, 2015 9:47 AM
  • User1133938822 posted

    Hi again,

    I have something like this:

    string uname = "";
            string strUsrID = TextBox1.Text;
            string strpswrd = TextBox2.Text;
            DirectoryEntry de = new DirectoryEntry("LDAP://DC=xxx,DC=xxx,DC=xx");
            de.Username = strUsrID;
            de.Password = strpswrd;
            DirectorySearcher ds = new DirectorySearcher(de);
            ds.SearchScope = SearchScope.Subtree;
            ds.Filter = "(&(objectCategory=User) (samAccountName=" + strUsrID + "))";
            ds.PropertiesToLoad.Add("sn");            // surname = last name
            ds.PropertiesToLoad.Add("givenName");  // given (or first) name
                SearchResult result = ds.FindOne();
                if (result != null)
                    uname = result.Properties[TextBox3.Text].ToString();
                    Label1.Text = "Error: Not found";
            catch (Exception f)
                Label1.Text = "Error:" + f.Message;

    How to change it to display all information from AD for user name in TextBox3.Text ??

    Thursday, October 15, 2015 7:42 AM
  • User1508394307 posted

    You display only specific attribute

    uname = result.Properties[TextBox3.Text].ToString();

    To display other attributes, you need to specify them

    string login = result.Properties["sAMAccountName"].ToString();
    string phone = result.Properties["telephoneNumber"].ToString();
    string email = result.Properties["mail"].ToString();

    Note, that some of the attributes might be indexed, i.e. might be designed for multiple values and might need to be called with index, e.g.

    string email = result.Properties["mail"][0].ToString();

    Also note that it might be required to tell to LDAP that you want to get specific parameter using PropertiesToLoad collection


    And if you want to display really all attributes, you could try to enumerate them as

    foreach (string property in result.Properties.PropertyNames)
        properties += property + "=" + result.Properties[property].ToString() + "; ";

    Hope this helps.

    Thursday, October 15, 2015 8:24 AM
  • User1133938822 posted

    Thanks. It's working. Now how to change those data and where can I find full list of parameters like sAMAccountName. Shortly, how to get any oher data (how they are called) ??

    Monday, October 19, 2015 2:53 AM
  • User1133938822 posted

    Nothing about it that you can help me ?

    Monday, October 26, 2015 11:42 AM