473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting user data from Active Directory

Hi,

I am trying to get user data (email data actually) from Active Directory.
What I exactly want to do is, getting the email address according to
username from the domain.
For example, when I enter my username DINCERM, it should give me
di*****@domain.com as result.

When I do this:
===
DirectoryEntry entry = new DirectoryEntry(LDAP://DENIZ);

DirectorySearcher searcher = new DirectorySearcher(entry);

searcher.Filter = " (&(objectClass=user)(objectCategory=person)(mail=* ))";

===

Then I can get all users with an email address available. But how will I be
able to filter it according to the username?

Thank you..



Nov 22 '05 #1
5 4761
Dincer,

Did you try this message in the newsgroup.
microsoft.public.dotnet.languages.csharp

Probably you have there a better change on an answer.

Cor
Nov 22 '05 #2
I will.. Thank you..

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eZ*************@TK2MSFTNGP09.phx.gbl...
Dincer,

Did you try this message in the newsgroup.
microsoft.public.dotnet.languages.csharp

Probably you have there a better change on an answer.

Cor

Nov 22 '05 #3
On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:

¤ Hi,
¤
¤ I am trying to get user data (email data actually) from Active Directory.
¤ What I exactly want to do is, getting the email address according to
¤ username from the domain.
¤ For example, when I enter my username DINCERM, it should give me
¤ di*****@domain.com as result.
¤
¤ When I do this:
¤ ===
¤ DirectoryEntry entry = new DirectoryEntry(LDAP://DENIZ);
¤
¤ DirectorySearcher searcher = new DirectorySearcher(entry);
¤
¤ searcher.Filter = " (&(objectClass=user)(objectCategory=person)(mail=* ))";
¤
¤ ===
¤
¤ Then I can get all users with an email address available. But how will I be
¤ able to filter it according to the username?
¤

See if the following works for you:

Public Function GetUserInfo(ByVal UserID As String)

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry )

Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
Console.WriteLine(UserFound.GetDirectoryEntry().Pr operties.Item("mail").Value)
End If

End Function
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #4
On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.pl> wrote:

¤ Hi,
¤
¤ I am trying to get user data (email data actually) from Active Directory.
¤ What I exactly want to do is, getting the email address according to
¤ username from the domain.
¤ For example, when I enter my username DINCERM, it should give me
¤ di*****@domain.com as result.
¤
¤ When I do this:
¤ ===
¤ DirectoryEntry entry = new DirectoryEntry(LDAP://DENIZ);
¤
¤ DirectorySearcher searcher = new DirectorySearcher(entry);
¤
¤ searcher.Filter = " (&(objectClass=user)(objectCategory=person)(mail=* ))";
¤
¤ ===
¤
¤ Then I can get all users with an email address available. But how will I be
¤ able to filter it according to the username?
¤

See if the following works for you:

Public Function GetUserInfo(ByVal UserID As String)

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry )

Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
If Not IsNothing(UserFound) Then
Console.WriteLine(UserFound.GetDirectoryEntry().Pr operties.Item("mail").Value)
End If

End Function
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #5
>For example, when I enter my username DINCERM, it should give me
di*****@domain.com as result.

DirectoryEntry entry = new DirectoryEntry(LDAP://DENIZ);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = " (&(objectClass=user)(objectCategory=person)(mail=* ))";


You'll need to add (samACcountName=DINCERM) to your filter, and also,
you'll need to specify which attributes you want to retrieve:

DirectorySearcher searcher = new DirectorySearcher("LDAP://DENIZ");

searcher.Filter = "
(&(objectClass=user)(objectCategory=person)(samAcc ountName=DINCERM))";

// add the mail property to the list of props to retrieve
// you can add any others you might be interested in, too!
searcher.PropertiesToLoad.Add("mail");

DirectoryEntry deUser = searcher.FindOne();
if(deUser != null)
{
Console.WriteLine("Your e-mail is: " +
deUser.Properties["mail"].Value.ToString();
}

Marc

================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Nov 22 '05 #6

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

Similar topics

4
893
by: Dinçer | last post by:
Hi, I am trying to get user data (email data actually) from Active Directory. What I exactly want to do is, getting the email address according to username from the domain. For example, when I...
1
3381
by: WIWA | last post by:
Hello, I have written a program that gets information from Active Directory. This is the function I'm using: void ADSysGetUserName(IADsADSystemInfo * pSys, char * data) { HRESULT hr; BSTR...
4
3844
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
3
12569
by: Dinçer | last post by:
Hi, I am trying to get user data (email data actually) from Active Directory. What I exactly want to do is, getting the email address according to username from the domain. For example, when I...
0
3444
by: Kenneth Keeley | last post by:
Hi, I am looking for a sample of how to get the password last set for a user in active directory in a format that we can read. I am using ASP.Net and C# I have got as far as get the value. but I...
5
2003
by: Diego F. | last post by:
Is it possible to get user password from active directory? I want to authenticate a user with Active Directory. I can get the name or email, but I don't know if I can get the password. --...
6
2391
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
0
2727
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
3
2234
by: Chakkaradeep | last post by:
Hi all, How to retrieve Users Names and also restrict internet access to a specific users using C# ? Thanks. Regards, C.C.Chakkaradeep
7
2770
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.