title: Disable User Account in Active Directory using C# Code
body: <p>I have created c# Winform application. via which I can disable an active directory user account using C# code. I have added a textbox in which I can enter my AD username. But unable to figure how to link this textbox entry with below code?</p>
  
  <pre><code>private static void DiableADUserUsingUserPrincipal(string username)
  {
      try
      {
          PrincipalContext principalContext = new PrincipalContext(ContextType.Domain); 
          UserPrincipal userPrincipal = UserPrincipal.FindByIdentity
                  (principalContext, username);
          userPrincipal.Enabled = false;
          userPrincipal.Save();
          Console.WriteLine("Active Directory User Account Disabled successfully through UserPrincipal");
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>