system.directoryservices usage

S

Sean

I figured I'd start this post on the .NET general forum instead of the
ADSI forum but feel free to nudge me along if I am looking in the wrong
place.

I am working with System.DirectoryServices to connect up to Active
Directory and make a couple of queries. The trouble starts as soon as I
attempt to compile this thing. I receive "Type
'System.DirectoryServices.SearchResultCollection' has no constructors." from
the following code. Since I'm in learning mode I am certain I'm doing
something wrong here. Any ideas where to go with this would be welcome.

Imports System.DirectoryServices

Partial Class companycontact

Inherits System.Web.UI.Page

Const ADConnectionString As String =
"LDAP://tirpitz.home.warnocksolutions.com"

Private Sub test_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles test.Click

Dim oConnection As New DirectoryEntry(ADConnectionString)

Dim oSearcher As New DirectorySearcher(oConnection)

Dim oSearchResults As New SearchResultCollection()

Dim oSearchResult As New SearchResult

oSearcher.Filter = "(objectClass=user)"

oSearchResults = oSearcher.FindAll()

For Each oSearchResult In oSearchResults

output.Text = oSearchResult.Properties("name").ToString

Next

End Sub

End Class
 
G

Guest

Sean,

Change the following line
Dim oSearchResults As New SearchResultCollection()
to
Dim oSearchResults As SearchResultCollection()

HTH, Jakob.
 
S

Siva M

Just remove New from the oSearchResults declaration line.

"Sean" <no spam> wrote in message
I figured I'd start this post on the .NET general forum instead of the
ADSI forum but feel free to nudge me along if I am looking in the wrong
place.

I am working with System.DirectoryServices to connect up to Active
Directory and make a couple of queries. The trouble starts as soon as I
attempt to compile this thing. I receive "Type
'System.DirectoryServices.SearchResultCollection' has no constructors." from
the following code. Since I'm in learning mode I am certain I'm doing
something wrong here. Any ideas where to go with this would be welcome.

Imports System.DirectoryServices

Partial Class companycontact

Inherits System.Web.UI.Page

Const ADConnectionString As String =
"LDAP://tirpitz.home.warnocksolutions.com"

Private Sub test_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles test.Click

Dim oConnection As New DirectoryEntry(ADConnectionString)

Dim oSearcher As New DirectorySearcher(oConnection)

Dim oSearchResults As New SearchResultCollection()

Dim oSearchResult As New SearchResult

oSearcher.Filter = "(objectClass=user)"

oSearchResults = oSearcher.FindAll()

For Each oSearchResult In oSearchResults

output.Text = oSearchResult.Properties("name").ToString

Next

End Sub

End Class
 
S

Sean

Thanks guys. Remind me to reread my code in the morning after playing
with this kind of thing at midnight.
 

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

Top