Identifying empty Active Directory attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pete Piper

    #1

    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 SearchResultCol lection = mySearcher.Find All()

    ' Iterate through each SearchResult in the SearchResultCol lection.

    Dim resEnt1 As SearchResult

    For Each resEnt1 In ResEnt

    If IsDBNull(resEnt 1.Properties("c ompany")) Then

    valueCompany = NoValueString

    Else

    valueCompany = resEnt1.Propert ies("company"). ToString

    'valueCompany = CStr(resEnt1.Pr operties("compa ny")(0))

    End If



  • =?Utf-8?B?ZG90TmV0RGF2ZQ==?=

    #2
    RE: Identifying empty Active Directory attributes

    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 ExtractADProper tyValue(ByVal propertyName As
    String, ByVal result As System.Director yServices.Searc hResult) As String

    Dim propertyValue As String = String.Empty

    If result.Properti es.Contains(pro pertyName) Then
    propertyValue = result.Properti es(propertyName ).Item(0).ToStr ing()
    End If

    Return propertyValue

    End Function

    =============== =============== ========
    David McCarter [Microsoft MVP]
    Improving Code Quality... One Developer at a Time

    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 SearchResultCol lection = mySearcher.Find All()
    >
    ' Iterate through each SearchResult in the SearchResultCol lection.
    >
    Dim resEnt1 As SearchResult
    >
    For Each resEnt1 In ResEnt
    >
    If IsDBNull(resEnt 1.Properties("c ompany")) Then
    >
    valueCompany = NoValueString
    >
    Else
    >
    valueCompany = resEnt1.Propert ies("company"). ToString
    >
    'valueCompany = CStr(resEnt1.Pr operties("compa ny")(0))
    >
    End If
    >
    >
    >
    >

    Comment

    Working...