AD application searches some data sn, givenName and telephoneNumber.
These are then pumped into label controls.
While sn and givenName are all full, telephoneNumber is not and each time I get System.NullReferenceException
This is how I tried (poorly) to solve the issue, but somehow it still pops up System.NullReferenceException
--code--
Dim rootEntry As New DirectoryEntry("GC://ou=Employee,ou=Users,dc=some,dc=weird,dc=com")
Dim searcher As New DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("sn")
searcher.PropertiesToLoad.Add("givenName")
searcher.PropertiesToLoad.Add("telephoneNumber")
searcher.PropertiesToLoad.Add("department")
searcher.Sort.Direction = SortDirection.Ascending
searcher.Sort.PropertyName = "sn"
searcher.Filter = "(&(&(objectCategory=person)(objectClass=user)(sn=*)))"
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
Dim props As ResultPropertyCollection
For Each result In results
props = result.Properties()
here I try to solve it
If props("telephoneNumber")(0) = " " Then
Label4.Text = "No Number"
End If
Dim counter As Integer
counter = counter + 1
Dim lblContent As New Label
lblContent.ID = "txtContent" & counter
lblContent.Text = props("sn")(0) & " " & props("givenName")(0) & " " & props("telephoneNumber")(0)
MyBase.Controls.Add(lblContent)
MyBase.Controls.Add(New LiteralControl("<br/>"))
Next
--code--
These are then pumped into label controls.
While sn and givenName are all full, telephoneNumber is not and each time I get System.NullReferenceException
This is how I tried (poorly) to solve the issue, but somehow it still pops up System.NullReferenceException
--code--
Dim rootEntry As New DirectoryEntry("GC://ou=Employee,ou=Users,dc=some,dc=weird,dc=com")
Dim searcher As New DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("sn")
searcher.PropertiesToLoad.Add("givenName")
searcher.PropertiesToLoad.Add("telephoneNumber")
searcher.PropertiesToLoad.Add("department")
searcher.Sort.Direction = SortDirection.Ascending
searcher.Sort.PropertyName = "sn"
searcher.Filter = "(&(&(objectCategory=person)(objectClass=user)(sn=*)))"
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
Dim props As ResultPropertyCollection
For Each result In results
props = result.Properties()
here I try to solve it
If props("telephoneNumber")(0) = " " Then
Label4.Text = "No Number"
End If
Dim counter As Integer
counter = counter + 1
Dim lblContent As New Label
lblContent.ID = "txtContent" & counter
lblContent.Text = props("sn")(0) & " " & props("givenName")(0) & " " & props("telephoneNumber")(0)
MyBase.Controls.Add(lblContent)
MyBase.Controls.Add(New LiteralControl("<br/>"))
Next
--code--