본문 바로가기

IT 관련 이야기/.NET

AD Handle C# Code Sample

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

'IT 관련 이야기 > .NET' 카테고리의 다른 글

silverlight4예제  (0) 2010.10.02
Linq 관련 샘플  (0) 2010.10.02
XMLHttp Handle 관련 좋은 Article.  (0) 2010.10.02
web.config 관련  (0) 2010.09.27
LDAP 관련 C# 프로그래밍 참조  (0) 2010.04.14
AD Handle C# Code Sample  (0) 2008.06.17

태그