q: code fails

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
 
J

Juan T. Llibre

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

Guest

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. :--)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top