q: code fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
The following code fails at Response.Write(result.Properties("mail")(0)) if
myUser does not have anything in the e-mail filed of active directory. The
message I am getting is “Object reference not set to an instance of an
objectâ€. How can I prevent from that?


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim userName As String
Dim rootEntry As New DirectoryEntry("LDAP://DC=MYDOMAIN,DC=net",
"MYDOMAIN\admin", "password")

Dim searcher As New DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("mail")
userName = "myUser"
searcher.Filter = "(&(anr=" & userName & ")(objectCategory=person))"

Dim results As SearchResultCollection
results = searcher.FindAll()

Dim result As SearchResult

For Each result In results
Response.Write(result.Properties("mail")(0))
Response.Write(result.Properties("cn")(0))
Next

End Sub
 
Jim,

Please don't send additional questions about
the same problem in separate threads.

This only clutters the issue.

See my reply in the original thread.




Juan T. Llibre
ASP.NET MVP
===========
 
Juan,
Thansk I thought you forgot me, that is why I had it here too. ANyway I
saloved the problem. I hope movie was good for you. :--)))
 
Back
Top