473,668 Members | 2,407 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);

DirectorySearch er searcher = new DirectorySearch er(entry);

searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";

===

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 4771
Dincer,

Did you try this message in the newsgroup.
microsoft.publi c.dotnet.langua ges.csharp

Probably you have there a better change on an answer.

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

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:eZ******** *****@TK2MSFTNG P09.phx.gbl...
Dincer,

Did you try this message in the newsgroup.
microsoft.publi c.dotnet.langua ges.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.p l> 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);
¤
¤ DirectorySearch er searcher = new DirectorySearch er(entry);
¤
¤ searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";
¤
¤ ===
¤
¤ 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(ByV al UserID As String)

Dim RootDSE As New DirectoryServic es.DirectoryEnt ry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Propert ies("DefaultNam ingContext").Va lue
Dim ADEntry As New DirectoryServic es.DirectoryEnt ry("LDAP://" & DomainDN)
Dim ADSearch As New System.Director yServices.Direc torySearcher(AD Entry)

Dim ADSearchResult As System.Director yServices.Searc hResult
ADSearch.Filter = ("(samAccountNa me=" & UserID & ")")
ADSearch.Search Scope = SearchScope.Sub tree
Dim UserFound As SearchResult = ADSearch.FindOn e()
If Not IsNothing(UserF ound) Then
Console.WriteLi ne(UserFound.Ge tDirectoryEntry ().Properties.I tem("mail").Val ue)
End If

End Function
Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #4
On Fri, 27 Aug 2004 11:14:49 +0300, "Dinçer" <dincer"AT"o2.p l> 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);
¤
¤ DirectorySearch er searcher = new DirectorySearch er(entry);
¤
¤ searcher.Filter = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";
¤
¤ ===
¤
¤ 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(ByV al UserID As String)

Dim RootDSE As New DirectoryServic es.DirectoryEnt ry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Propert ies("DefaultNam ingContext").Va lue
Dim ADEntry As New DirectoryServic es.DirectoryEnt ry("LDAP://" & DomainDN)
Dim ADSearch As New System.Director yServices.Direc torySearcher(AD Entry)

Dim ADSearchResult As System.Director yServices.Searc hResult
ADSearch.Filter = ("(samAccountNa me=" & UserID & ")")
ADSearch.Search Scope = SearchScope.Sub tree
Dim UserFound As SearchResult = ADSearch.FindOn e()
If Not IsNothing(UserF ound) Then
Console.WriteLi ne(UserFound.Ge tDirectoryEntry ().Properties.I tem("mail").Val ue)
End If

End Function
Paul ~~~ pc******@amerit ech.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.

DirectoryEnt ry entry = new DirectoryEntry( LDAP://DENIZ);
DirectorySearc her searcher = new DirectorySearch er(entry);
searcher.Filte r = " (&(objectClass= user)(objectCat egory=person)(m ail=*))";


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

DirectorySearch er searcher = new DirectorySearch er("LDAP://DENIZ");

searcher.Filter = "
(&(objectClass= user)(objectCat egory=person)(s amAccountName=D INCERM))";

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

DirectoryEntry deUser = searcher.FindOn e();
if(deUser != null)
{
Console.WriteLi ne("Your e-mail is: " +
deUser.Properti es["mail"].Value.ToString ();
}

Marc

=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)i nova.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 enter my username DINCERM, it should give me dincerm@domain.com as result. When I do this: ===
1
3387
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 bstr; hr = pSys->get_UserName(&bstr); if (SUCCEEDED(hr)) {
4
3868
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
12575
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 enter my username DINCERM, it should give me dincerm@domain.com as result. When I do this: ===
0
3498
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 would like it as a normal date time value. or at least display it as a string. if I use the code below the response I get is "The password was last set :System.__ComObject" How do I get this to a norma date format. Thanks
5
2014
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. -- Regards, Diego F.
6
2408
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 Idea about ASP.net Please Help Thanks in Advance.
0
2739
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 ------------------------------------------------- To map a certificate to a user account Open Active Directory Users and Computers.
3
2239
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
2777
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 developing web based application for my small office. I put my Apache+php+MySQL in Win2003 Server. My Clients using IE as default browser. What i want to do is to integrated active directory user with my application.
0
8382
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6209
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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 we have to send another system
2
1787
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.