윈도우폰 세상/Windows Phone

소년포비 2009. 10. 21. 06:38

AD  Handle C# Code Sample
원본 : http://theagussantoso.blogspot.com/2008/01/k2-tips-and-trick-january-2008.html

case : Suppose you want to get Codi's full name from active directory (login name : denallix\codi). You can use this code.


public string GetFullName(string userID)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://DENALLIX.COM");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(SAMAccountName=" + userID + ")";
searcher.PropertiesToLoad.Add("displayname");

SearchResult result = searcher.FindOne();

return result.Properties["displayname"][0].ToString();
}


Sample code : string myFullName = GetFullName("codi"); //returns Codi


Common problem #2: Get Active Directory's Email from Login Name

case : Suppose you want to get Codi's email from active directory (login name : denallix\codi).


public string GetEmail(string userID)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://DENALLIX.COM");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(SAMAccountName=" + userID + ")";
searcher.PropertiesToLoad.Add("mail");

SearchResult result = searcher.FindOne();

return result.Properties["mail"][0].ToString();
}

Sample code : string myFullName = GetEmail("codi"); //returns codi@denallix.com