"Ziemowit" <zi*******@wp.pl> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
No problem, examples directly from my code with short comments:
public string GetDisplayName(string cn) //cn is unique for user
{
string FullName = "";
try
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://server/DC=yourdomain,DC=com"); //path for
server that store AD, can be domain server
entry.AuthenticationType = AuthenticationTypes.ReadonlyServer; //we
want only readonly access
entry.Username = "username"; //if domain allow anonymous access
to AD application then these two rows are not required
entry.Password = "password"; //if not, then you will need domain
account to acces to AD server
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(cn="+cn+")";
search.PropertiesToLoad.Add("displayName"); //name of property to
load
SearchResult sr = search.FindOne();
if (sr != null)
{
FullName = sr.Properties["displayName"][0].ToString(); //read
property
}
search.Dispose();
entry.Dispose();
}
catch
{
}
return FullName; //thats all
}
You have to check if your application have access to AD server and
create domain account if required. To get info what LDAP paths should
be I suggest you to use LDAPBrowser - cool software for browsing LDAP.
I hope it helps
Ziemowit
I'm a vb user and c# is a bit greek to me but I think I can adapt and
overcome. :)
Yesterday I went through the System.DirectoryServices.ActiveDirectory
namespace in hopes of finding something useful in there for my purposes and
after getting lost of a while, was unable to find anything to suit my
purpose. Oh well.
Thanks for the help. I'll put it to good use.
Jim