Using .NET DirectoryServices to access an AD Attribute

Using .NET DirectoryServices to access an AD Attribute

Post by Dave » Fri, 18 Oct 2002 01:37:30



I am interested in disecting the blob of data that a specialist
application stores in the extensionData attribute in AD ( which
ADSIEdit shows to be an OctetString ).  I have tried using the
following ( cribbed ) code :

Dim root As New DirectoryServices.DirectoryEntry("LDAP://home/cn=Users,dc=home,dc=home,dc=com")
        Dim searcher As New DirectoryServices.DirectorySearcher(root)
        Dim results As SearchResultCollection
        Dim result As SearchResult

        searcher.Filter = "(mailNickname=dave)"
        searcher.PropertiesToLoad.Add("displayName")
        searcher.PropertiesToLoad.Add("telephoneNumber")
        searcher.PropertiesToLoad.Add("extensionData")

        results = searcher.FindAll()

        For Each result In results

            Console.WriteLine(result.Properties("displayName")(0))
            Console.WriteLine(result.Properties("telephoneNumber")(0))
            Console.WriteLine(result.Properties("extensionData")(0))

        Next result

Although the display name and telephone number attributes are written
correctly to the console, the extensionData attribute is written as
"System.Byte[]".  As a complete VB/.NET beginner I don't really
understand what this is telling me.

How should I address, read and manipulate this attribute ?

Thanks

 
 
 

Using .NET DirectoryServices to access an AD Attribute

Post by Jeff Jones [MS » Fri, 18 Oct 2002 02:11:31


Since System.Byte[] doesn't overwrite the System.Object ToString() method
you are getting the default ToString() which outputs the class type.  So in
order for you to use this Byte[] you have to case it from System.Object to
System.Byte[].

I'm not familiar with VB but in C# it would look something like:
System.Byte[] byteArray =
(System.Byte[])result.Properties["extensionData"].Value;

From this point you can use byteArray as a System.Byte[].  ADSI Edit would
loop through each byte converting it to a string representation in hex,
decimal, or whatever format you select.
--
Jeff Jones [MS]
Active Directory Administration Tools Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:> I am interested in disecting the blob of data that a specialist
> application stores in the extensionData attribute in AD ( which
> ADSIEdit shows to be an OctetString ).  I have tried using the
> following ( cribbed ) code :

> Dim root As New

DirectoryServices.DirectoryEntry("LDAP://home/cn=Users,dc=home,dc=home,dc=co
m")
Quote:>         Dim searcher As New DirectoryServices.DirectorySearcher(root)
>         Dim results As SearchResultCollection
>         Dim result As SearchResult

>         searcher.Filter = "(mailNickname=dave)"
>         searcher.PropertiesToLoad.Add("displayName")
>         searcher.PropertiesToLoad.Add("telephoneNumber")
>         searcher.PropertiesToLoad.Add("extensionData")

>         results = searcher.FindAll()

>         For Each result In results

>             Console.WriteLine(result.Properties("displayName")(0))
>             Console.WriteLine(result.Properties("telephoneNumber")(0))
>             Console.WriteLine(result.Properties("extensionData")(0))

>         Next result

> Although the display name and telephone number attributes are written
> correctly to the console, the extensionData attribute is written as
> "System.Byte[]".  As a complete VB/.NET beginner I don't really
> understand what this is telling me.

> How should I address, read and manipulate this attribute ?

> Thanks