ADHelper - An Active Directory Class


Working on my latest project required quite a degree of development against the Active Directory. Not having had any AD experience before slowed me down for a while, but after trawling through lost of news groups etc, I gathered enough information to do what I needed to do.

I have developed an ADHelper class that will should take care of most AD requirements, from :-

  • creating/updating a user
  • assigning a user to a group
  • enabling/disabling their account
  • setting password
  • checking if a user is valid
  • loggin in
  • checking if a user exists
  • performing queries

All while returning DataSets to allow easy binding to datagrids etc.

Im by no means an expert, but hopefully this helps some of you facing the same problems that I had.

NOTES
=====

This class will return a mix of ActiveDirectory 'DirectoryEntry' objects and DataSets that u can plug into your business layer

The first couple of lines that set the following private varables, need to be changed so that the 'Configuration' is the .Net ConfigurationSettings.AppSettings["xxx"].ToString, as the configuration object is a custom one that has not been included.

private static string ADPath=Configuration.ADFullPath ;
private static string
ADUser = Configuration.ADAdminUser ;
private static string ADPassword = Configuration.ADAdminPassword ;

Change to :-

private static string ADPath=ConfigurationSettings.AppSettings["ADFullPath"].ToString() ;
private static string
ADUser = ConfigurationSettings.AppSettings["ADAdminUser"].ToString() ;
private static string ADPassword = ConfigurationSettings.AppSettings["ADAdminPassword"].ToString() ;