title: How to update data in Active Directory using DirectoryEntry?
body: <p>I want to update user expire date in Active Directory. If already have user then update expire date. I try to call <code>CommitChanges</code> with this code:</p>
  
  <pre><code>if (result == null)
  {
      DirectoryEntry newUser = dirEntry.Children.Add("CN=" + fNm, "user");
      newUser.Properties["sAMAccountName"].Value = uNm;
      newUser.Properties["givenName"].Value = fNm;
      newUser.Properties["sn"].Value = lNm;
      newUser.Properties["displayName"].Value = NID_Number;
  
      dateEng = DateTime.Today.AddDays(3); ;
  
      newUser.Properties["accountExpires"].Value = dateEng.ToFileTime().ToString();
  
      newUser.Properties["userPrincipalName"].Add(uNm + "@pkru.ac.th");
      newUser.CommitChanges();
      oGUID = newUser.Guid.ToString();
  
      const int UF_NORMAL_ACCOUNT = 0x0200;
      const int UF_DONT_EXPIRE_PASSWD = 0x10000;
      newUser.Properties["userAccountControl"].Value = UF_NORMAL_ACCOUNT + UF_DONT_EXPIRE_PASSWD;
      newUser.Invoke("SetPassword", new object[] { NID_Number });
  
      newUser.CommitChanges();
  
      dirEntry.Close();
      newUser.Close();
  }
  else
  {
      gp = SearchUserGroup(result);
  
      if (string.Equals(gp, "ABC"))
      {
          dateEng = DateTime.Today.AddDays(7); ;
          DirectoryEntry newUser = dirEntry.Children.Add("CN=" + fNm, "user");
          newUser.Properties["accountExpires"].Clear();
          newUser.Properties["accountExpires"].Value = dateEng.ToFileTime().ToString();
          newUser.CommitChanges();
      }
  }
  </code></pre>
  
  <p>When I run it show error like this.</p>
  
  <blockquote>
    <p>at System.DirectoryServices.DirectoryEntry.CommitChanges()<br>
    at NIDCardCS.Form1.AddToAD(String fNm, String lNm, String uNm, String) in C:\Users\Test\Form1.cs:line 289<br>
    Exception thrown: 'System.DirectoryServices.DirectoryServicesCOMException' in System.DirectoryServices.dll<br>
    System.DirectoryServices.DirectoryServicesCOMException (0x80071392): The object already exists.</p>
  </blockquote>
  
  <p>How to update data in Active Directory using <code>DirectoryEntry</code> ?</p>