468,727 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

Identifying empty Active Directory attributes

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

Feb 12 '08 #1
1 3577
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
"Pete Piper" wrote:
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

Feb 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
3 posts views Thread by tornado | last post: by
6 posts views Thread by Tung Wai Yip | last post: by
9 posts views Thread by Mario Rodriguez | last post: by
13 posts views Thread by could ildg | last post: by
1 post views Thread by Keith Jakobs, MCP | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
xarzu
1 post views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.