getting user data from Active Directory

  • Thread starter Thread starter Dinçer
  • Start date Start date
D

Dinçer

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
(e-mail address removed) 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..
 
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
 
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
¤ (e-mail address removed) 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().Properties.Item("mail").Value)
End If

End Function


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
For example, when I enter my username DINCERM, it should give me
(e-mail address removed) 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)(samAccountName=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
 
Back
Top