473,785 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About 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 16 '05 #1
3 12580
Dinçer,

I'm not that familiar with AD, but when you set the Filter property, it
appears that you are setting a filter to allow all instances of the mail
property to show up. Can't you just add to that filter for the username
property as well?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dinçer" <dincer"AT"o2.p l> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
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 16 '05 #2
You need to query on the "SAMAccountName " field
See this example:
http://dotnetjunkies.com/WebLog/robw...1/28/6228.aspx

Hope this helps,
--- Nick

"Dinçer" <dincer"AT"o2.p l> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
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 16 '05 #3
>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 16 '05 #4

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

Similar topics

1
1790
by: Keith | last post by:
How would I go about extracting information from Active Directory using an ASP page so I can display things like the phone number, name, address etc. which are stored there? Thanks
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
5218
by: elziko | last post by:
Hi, I'm using the following code to create a user: Dim strNodeName As String = "test user" Dim NewUser As DirectoryEntry Dim AD As New DirectoryEntry("WinNT://MYCOMPUTER") 'delete user when existing Try
1
3391
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
3884
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
1
7314
by: anonymous | last post by:
Hi all, I've been searching the way to achieve the following task. But no luck so far. I have a web site(main site), which requires authentication. This authentication is set at Windows directory level, so user will see the pop up gray box in order to log in rather than custom web page. The username and password are stored at active directory level, thus this is the windows integrated security.
6
2417
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.
2
1318
by: NathanC | last post by:
'*********************************************** Dim MySearcher As New DirectorySearcher("LDAP://CN=Users,DC=corporate,DC=domainname,DC=com") ' Create a DirectorySearcher object. Dim resEnt As SearchResult = MySearcher.FindOne() 'Now what? None of the examples are getting what I need '***********************************************
3
4109
usafshah
by: usafshah | last post by:
is it possible to check current password for a user in Active Directory
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
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...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
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
5396
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...
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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.