IxiRancid Posted March 7, 2005 Posted March 7, 2005 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-- Quote
eramgarden Posted March 7, 2005 Posted March 7, 2005 are u getting the info from database in SQL? if so, you do "select whatever, whatever, isnull(telephoneNumber,'') from whereever.." Quote
IxiRancid Posted March 8, 2005 Author Posted March 8, 2005 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 Quote
IxiRancid Posted March 8, 2005 Author Posted March 8, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.