Identifying empty Active Directory attributes

P

Pete Piper

Hi

I am trying to extract user data from Active Directory and locate it in an
offline Access database for reporting. The problem I have is when I came
acrsoss an object where an attribute is empty.

I tried to trap this with an isDBnull call (as below) but this does not
work - is it possible to identify null attributes in an Active Directory
SearchResult?

Ta PP

Dim ResEnt As SearchResultCollection = mySearcher.FindAll()

' Iterate through each SearchResult in the SearchResultCollection.

Dim resEnt1 As SearchResult

For Each resEnt1 In ResEnt

If IsDBNull(resEnt1.Properties("company")) Then

valueCompany = NoValueString

Else

valueCompany = resEnt1.Properties("company").ToString

'valueCompany = CStr(resEnt1.Properties("company")(0))

End If
 
D

dotNetDave

Here is what I use to extract AD properties so it does not produce any
problems. I hope you find it useful.

Private Shared Function ExtractADPropertyValue(ByVal propertyName As
String, ByVal result As System.DirectoryServices.SearchResult) As String

Dim propertyValue As String = String.Empty

If result.Properties.Contains(propertyName) Then
propertyValue = result.Properties(propertyName).Item(0).ToString()
End If

Return propertyValue

End Function

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://www.cafepress.com/geekmusicart.1654787045
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top