Outlook "Check Names" feature in visual basic.net or C#

- First check out the image attached.
- Suppose I have an asp.net form containing a text field and a button and a list box. I type my windows user name (or part of user name) in the text field and then press button. What i want is that it should check what ever is in text field when i hit button and try to match all email addresses or user names in domain active directory and display their email addresses in list box. Otherwise it should return "no user match".


Screenshot.JPG
LVL 5
Khalid Mehmood AwanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
I assume that you want to search for users in your active directory.
Some starting points:
Using Active Directory In ASP.NET - Enumerate Active Directory Users
http://www.codeproject.com/KB/aspnet/adsi2.aspx

Searching Active Directory for Users and Groups
http://www.eggheadcafe.com/articles/20051106.asp

Howto: (Almost) Everything In Active Directory via C#
http://www.codeproject.com/KB/system/everythingInAD.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
And for auto complete, check this video

http://www.asp.net/learn/AJAX-videos/video-122.aspx
0
Khalid Mehmood AwanAuthor Commented:
One code snippet is attached, the other is here ... This solved my issue.

 Public Shared Function AuthenticateUserPassword(ByVal szUserName As String, ByVal szPassword As String) As Boolean
        Dim result As Boolean = False
        Dim szUserDomain As String = ""
        Dim myLDAPPath As String

        ' Determine what the domain name should be.
        If szUserName.Contains("\") Then
            ' Pull the domain out of the user name.
            szUserDomain = szUserName.Substring(0, szUserName.IndexOf("\"))
            ' Set user name to just user name.
            szUserName = szUserName.Substring(szUserName.IndexOf("\") + 1)
        ElseIf szUserName.Contains("@") Then
            ' User Name is in form of "user@domain"
            ' Pull the domain out of the user name.
            szUserDomain = szUserName.Substring(szUserName.IndexOf("@") + 1)
            ' Set user name to just user name.
            szUserName = szUserName.Substring(0, szUserName.IndexOf("@"))
        Else
            ' A "." refers to the local system.
            szUserDomain = Environment.MachineName
            szUserName = szUserName.Substring(szUserName.IndexOf("\") + 1)
        End If

        ' Determine which entry it will need to be.
        If String.Compare(szUserDomain, Environment.MachineName, True) = 0 Then
            myLDAPPath = "WinNT://" & szUserDomain
        Else
            myLDAPPath = "LDAP://" & szUserDomain
        End If

        Try
            Dim entry As DirectoryEntry = New DirectoryEntry(myLDAPPath, szUserName, szPassword)
            Dim nativeObject As Object = entry.NativeObject
            result = True 'no exception thrown, user must exist
            nativeObject = Nothing  'be sure and clean up these object as this service could be used many times
            entry = Nothing
        Catch ex As Exception
            result = False  'exception thrown - no user with that name/pwd combination
        End Try
        Return result
    End Function
Public Shared Function AD(ByVal strQuery As String, ByVal strReturn As String, ByRef listbox1 As ListBox)
        If strQuery = "" Then
            Exit Function
        End If
        'strQuery = "khalid.mehmood@mobilink.net"

        Dim oroot As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry("LDAP://mobilink")
        Dim osearcher As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(oroot)
        Dim result As DirectoryServices.SearchResult
        Dim resultAll As DirectoryServices.SearchResultCollection
        'osearcher.Filter = "(&(objectCategory=person)(objectClass=user)(mail=" & strQuery & "))"  ' search filter
        osearcher.Filter = "(&(anr=" & strQuery & ")(mail=*))"  ' search filter
        resultAll = osearcher.FindAll()

        If resultAll.Count > 0 Then
            For i As Integer = 0 To (resultAll.Count - 1)
                listbox1.Items.Add(resultAll(i).Properties("mail")(0).ToString())
            Next
        End If

        oroot = Nothing
        osearcher = Nothing
        result = Nothing
        resultAll = Nothing

        Exit Function
End Function

Open in new window

0
Khalid Mehmood AwanAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.