NullException

IxiRancid

Well-known member
Joined
Jun 16, 2004
Messages
104
Location
Europe
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--
 
are u getting the info from database in SQL?

if so, you do "select whatever, whatever, isnull(telephoneNumber,) from whereever.."
 
I get info... this is Active Directory searcher (DirectoryServices).
I can see surnames, given names, but I dont get phones because some of the entries dont have any data.

searcher.Filter = "(&(&(objectCategory=person)(objectClass=user)(sn=*)(!telephoneNumber=nothing/null))"

Doesnt do anything... its supposed to be ! (NOT) telephoneNumber=null or nothing
 
Solved

I solved my problem. The thing is, user searches only (or is interested) for telephoneNumber. So I incorporated into my search two filters/conditions

1. department is filtered by a TextBox control
AND
2. telephoneNumber is filtered IF EXISTS (or ONLY those with) ELSE dont try to display it

this is the actual LDAP dialect filter statement:

searcher.Filter = "(&(&(&(objectCategory=person)(objectClass=user))(department=*" + txtOddelek.Text + "))(telephoneNumber=*))"

This does not solve the issue of null values in Active Direcotry, but thats a whole new subject for our SysAdmins :D
 
Back
Top