How to assign default values in DirectoryServices?

richee

New member
Joined
Jun 10, 2005
Messages
2
Programming Experience
Beginner
Hi all,

Does anyone out there know how to avoid getting an ArgumentOutOfRangeException when using the DirectoryServices namespace.

Basically I`ve got an LDAP lookup tool that I developed to populate some call tracking software. This works fine but if it comes accross a field in the DB which is empty it throws an exception (of course). The problem is that with the result.properties method it doesnt seem possible to either get it to return a default value on nothing or to define a default value in the code. Here is a snippet to give you the idea.



...
searcher.PropertiesToLoad.Add("givenName")
searcher.PropertiesToLoad.Add("employeeNumber")
searcher.PropertiesToLoad.Add("sn")
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("co")
searcher.PropertiesToLoad.Add("telephoneNumber")
searcher.PropertiesToLoad.Add("mail")
searcher.PropertiesToLoad.Add("MRUCode")
searcher.PropertiesToLoad.Add("BusinessUnit")
Dim results As System.DirectoryServices.SearchResultCollection

Try

results = searcher.FindAll()
Catch ex As System.Exception
Console.WriteLine(ex.Message)
End Try

Dim result As System.DirectoryServices.SearchResult
For Each result In results

Console.WriteLine(result.Properties("givenName")(0))
Console.WriteLine(result.Properties("employeeNumber")(0))
Console.WriteLine(result.Properties("sn")(0))
Console.WriteLine(result.Properties("cn")(0))
Console.WriteLine(result.Properties("co")(0))
Console.WriteLine(result.Properties("telephoneNumber")(0))
Console.WriteLine(result.Properties("mail")(0))
Console.WriteLine(result.Properties("MRUCode")(0))
Console.WriteLine(result.Properties("BusinessUnit")(0))
...etc

I hope i made it clear.

Thanks a million,

Richee




 
Back
Top