Parameter in a directorysearcher.filter?

Discussion in 'ASP .Net' started by Jay, Apr 14, 2004.

  1. Jay

    Jay Guest

    I need to add a parameter to a directorysearcher.filter rather than using
    hard-coded text. I have the following code that finds all members of an AD
    group and then for each of those results tries to find that users
    samAccountName.

    Perhaps I'm going about this incorrectly but I know if I could pass my
    searcher.filter a paramter rather than typing "cn=jason", etc this code
    would work, any help would be very much appreciated!:

    'Get all users in the G_SCA_Change_Control_Approvers group

    Dim Approvers_entry As New
    DirectoryEntry("LDAP://CN=G_SCA_Change_Control_Approvers,OU=Groups,DC=sca,DC
    =hin,DC=sk,DC=ca")

    Dim Approvers_result As String

    Dim entry As New DirectoryEntry("LDAP://SCA")

    Dim searcher As New DirectorySearcher(entry)

    Dim result As SearchResult

    Dim results As SearchResultCollection

    searcher.PropertiesToLoad.Add("samAccountName")

    For Each Approvers_result In Approvers_entry.Properties("member")

    Approvers_result = Approvers_result.ToString.Split(",")(0)

    Approvers_result = Approvers_result.ToString.Split("=")(1)

    txtADUserGroup.Text = txtADUserGroup.Text & Approvers_result & vbNewLine

    searcher.Filter = String.Format("(&(objectClass=person)(cn=<Approvers-result
    needs to go here rather than having to type the cn of the user>))")

    result = searcher.FindOne

    txtADUserGroup.Text = txtADUserGroup.Text &
    result.Properties("samAccountName")(0).ToString() & vbNewLine

    Next


    Thanks in advance,

    Jason
    Jay, Apr 14, 2004
    #1
    1. Advertising

  2. Jay

    Jay Guest

    In case anyone else is having this issue, I'm able to toss a variable into
    my directorysearcher.filter with the following code -- This code gathers all
    members of a particular group in Active Directory, finds their
    samAccountName and populates a checkboxlist with these values:
    'Get all users in the G_SCA_Change_Control_Approvers group

    Dim Approvers_entry As New
    DirectoryEntry("LDAP://CN=G_SCA_Change_Control_Approvers,OU=Groups,DC=sca,DC
    =hin,DC=sk,DC=ca")

    Dim Approvers_result As String

    Dim entry As New DirectoryEntry("LDAP://SCA")

    Dim searcher As New DirectorySearcher(entry)

    Dim result As SearchResult

    Dim results As SearchResultCollection

    searcher.PropertiesToLoad.Add("samAccountName")

    'Get the members of the group

    For Each Approvers_result In Approvers_entry.Properties("member")

    Approvers_result = Approvers_result.ToString.Split(",")(0)

    Approvers_result = Approvers_result.ToString.Split("=")(1)

    'Find the samAccountName of the current Approvers_result

    searcher.Filter = ("(&(objectClass=person)(cn=" & Approvers_result & "))")

    result = searcher.FindOne

    'Fill Approvers checkbox lists with member's samAccountName property

    cblApprovers.Items.Add(New
    ListItem(result.Properties("samAccountName")(0).ToString))

    Next


    "Jay" <> wrote in message
    news:...
    > I need to add a parameter to a directorysearcher.filter rather than using
    > hard-coded text. I have the following code that finds all members of an

    AD
    > group and then for each of those results tries to find that users
    > samAccountName.
    >
    > Perhaps I'm going about this incorrectly but I know if I could pass my
    > searcher.filter a paramter rather than typing "cn=jason", etc this code
    > would work, any help would be very much appreciated!:
    >
    > 'Get all users in the G_SCA_Change_Control_Approvers group
    >
    > Dim Approvers_entry As New
    >

    DirectoryEntry("LDAP://CN=G_SCA_Change_Control_Approvers,OU=Groups,DC=sca,DC
    > =hin,DC=sk,DC=ca")
    >
    > Dim Approvers_result As String
    >
    > Dim entry As New DirectoryEntry("LDAP://SCA")
    >
    > Dim searcher As New DirectorySearcher(entry)
    >
    > Dim result As SearchResult
    >
    > Dim results As SearchResultCollection
    >
    > searcher.PropertiesToLoad.Add("samAccountName")
    >
    > For Each Approvers_result In Approvers_entry.Properties("member")
    >
    > Approvers_result = Approvers_result.ToString.Split(",")(0)
    >
    > Approvers_result = Approvers_result.ToString.Split("=")(1)
    >
    > txtADUserGroup.Text = txtADUserGroup.Text & Approvers_result & vbNewLine
    >
    > searcher.Filter =

    String.Format("(&(objectClass=person)(cn=<Approvers-result
    > needs to go here rather than having to type the cn of the user>))")
    >
    > result = searcher.FindOne
    >
    > txtADUserGroup.Text = txtADUserGroup.Text &
    > result.Properties("samAccountName")(0).ToString() & vbNewLine
    >
    > Next
    >
    >
    > Thanks in advance,
    >
    > Jason
    >
    >
    Jay, Apr 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cameron

    DirectorySearcher & sorting

    cameron, Jul 4, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    4,731
    Yan-Hong Huang[MSFT]
    Jul 7, 2003
  2. dave
    Replies:
    0
    Views:
    752
  3. Roger Bavaud

    DirectorySearcher Filter Exchange Server

    Roger Bavaud, Nov 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    594
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 5, 2004
  4. mike
    Replies:
    4
    Views:
    3,587
  5. Replies:
    0
    Views:
    683
Loading...

Share This Page