Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

Reading AD Attributes

Last post 02-02-2010, 3:04 PM by joe. 1 replies.
Sort Posts: Previous Next
  •  02-02-2010, 12:25 PM 7771

    Reading AD Attributes

    i am trying to read the values for gPOptions and gPOLinks from each OU in the domain. the code blow reads the name attribute with out any problems but when I try to get either of the gpo attributes i get a NullReferenceException  e = {"Object reference not set to an instance of an object."}

    DirectoryEntry direntry = new DirectoryEntry(objectDn)
    strValue = direntry.Properties[attributeName].Value.ToString();

    i have done a watch on all the objects that this function is using, but i am missing something that is going on with these two attributes.



  •  02-02-2010, 3:04 PM 7775 in reply to 7771

    Re: Reading AD Attributes

    Two quick things:

    • Make sure you spell the attribute names right (gpOptions and gpLink; not case sensitive)
    • Make sure they aren't null. If you call ToString on the .Value property and the attribute value in the directory is empty, you'll get this exception. You should test for null first.

    If you are sure the attribute is populated on the object with the DN you are using but you can't read it after correcting spelling, then the likely issue would be permissions. Users who don't have permissions to read an attribute experience that as if the attribute value does not exist at all. Hopefully that's not the issue.

View as RSS news feed in XML