Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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--

Posted

I get info... this is Active Directory searcher (DirectoryServices).

I can see surnames, given names, but I don't get phones because some of the entries don't have any data.

 

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

 

Doesn't do anything... it's supposed to be ! (NOT) telephoneNumber=null or nothing

Posted

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 don't 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 that's a whole new subject for our SysAdmins :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...