473,387 Members | 1,520 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,387 software developers and data experts.

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);

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 16 '05 #1
3 12559
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.com

"Dinçer" <dincer"AT"o2.pl> wrote in message
news:%2***************@TK2MSFTNGP09.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);

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 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.pl> wrote in message
news:%2***************@TK2MSFTNGP09.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);

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 16 '05 #3
>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 16 '05 #4

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

Similar topics

1
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
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
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...
1
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
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
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...
6
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...
2
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...
3
usafshah
by: usafshah | last post by:
is it possible to check current password for a user in Active Directory
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.