473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

LDAP search to DataGrid from sample code

Could some kind soul please explain to me how i could implement this in a
DataGrid.
I found the sample here.
http://www.wwwcoder.com/main/parenti...8/default.aspx
I'm a complete noob so any help is appreciated.

Rgds
Dave

'####################
'Sample Code
'####################
Public Class ActiveDirectory

'In the following function we will pass the Sam account name to the
function. This can be obtained by reference the Context.User.Indentity.Name
object in .Net. or by referring to the Request.Servervariables("LOGON_USER")
object. The second value passed to the function is the property of the user
class in Active Directory that you want to get a value of.

Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
As String

Try

Dim sPath As String = "LDAP://domain.com/DC=domain,DC=com"

Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))

Dim myDirectory As New DirectoryEntry(sPath, "administrator", "password")
'pass the user account and password for your Enterprise admin.

Dim mySearcher As New DirectorySearcher(myDirectory)

Dim mySearchResultColl As SearchResultCollection

Dim mySearchResult As SearchResult

Dim myResultPropColl As ResultPropertyCollection

Dim myResultPropValueColl As ResultPropertyValueCollection

'Build LDAP query

mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount &
"))")

mySearchResultColl = mySearcher.FindAll()

'I expect only one user from search result

Select Case mySearchResultColl.Count

Case 0

Return "Null"

Exit Function

Case Is > 1

Return "Null"

Exit Function

End Select

'Get the search result from the collection

mySearchResult = mySearchResultColl.Item(0)

'Get the Properites, they contain the usefull info

myResultPropColl = mySearchResult.Properties

'displayname, mail

'Retrieve from the properties collection the display name and email of the
user

myResultPropValueColl = myResultPropColl.Item(inType)

Return CStr(myResultPropValueColl.Item(0))

Catch ex As System.Exception

'do some error return here.

End Try

End Function

'Here we will just create some variables and populate them with the call to

'the GetUserInfo function by passing the user account and name of the
property we want to get.

Dim sEmail As String = GetUserInfo(UserAccount, "mail")

Dim sFirstName As String = GetUserInfo(UserAccount, "givenName")

Dim sLastName As String = GetUserInfo(UserAccount, "sn")

Dim sCity As String = GetUserInfo(UserAccount, "l")

Dim sState As String = GetUserInfo(UserAccount, "st")

Dim sStreetAddress As String = GetUserInfo(UserAccount, "streetAddress")

Dim sPostalCode As String = GetUserInfo(UserAccount, "postalCode")

Dim sPhone As String = GetUserInfo(UserAccount, "telephoneNumber")

Dim sCountry As String = GetUserInfo(UserAccount, "co")

End Class
Nov 19 '05 #1
0 1245

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dirk Hagemann | last post by:
Hi! I asked here a few weeks ago the same question but the answer of Tim Golden didn't really help yet. I'd like to know how to set up a query for all computer-accounts in a special part of...
7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
2
by: Chandy | last post by:
Hi, I have found some sample code for accessing active directory using the LDAP provider to check a user's credentials. The sample looks good but I do not understand the point of two lines. ...
3
by: Dennis Dobslaf | last post by:
I try to do some authentication with LDAP. But it's a bit different to the sample in msdn. I wrote a class LdapAuthentication with a method public bool IsAuthenticated(String domain, String...
1
by: Dave | last post by:
Could someone fix this for me please. The last bit i cant figure out is the last line in the sub. Results.SetDataBinding(myTable.DefaultView, "") Thanks Dave ...
2
by: Brad | last post by:
I'm extracting info for users and group in our domain using directoryservices. This is working well except I have one more piece I need to finish which I'm stuck on. I need to (a) query the info...
1
by: Serge | last post by:
Good Day Folks, I'm still trying to write a class to do LDAP searches on a Novell eDirectory. I've yet to see anything that even compiles, this includes samples from MSDN. Amazing. I...
2
by: P Webster | last post by:
We recently moved a web site that validated user credentials in Active Directory from IIS 5.1 to IIS 6, and the validation code no longer works. The web.config file is set to Windows authentication...
3
by: RJN | last post by:
Hi I've written a code that queries Windows LDAP server and works fine, but the same doesn't work when querying Solaris LDAP server. DirectoryEntry de = new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.