Dim strFullName As String = GetRealNameFromAd(User.Identity.Name)
Private Function GetRealNameFromAd(ByVal UsernameToFind As String) As String Using searcher As New DirectorySearcher(New DirectoryEntry()) searcher.PageSize = 1000 searcher.SearchScope = SearchScope.Subtree searcher.Filter = "(&(samAccountType=805306368)(sAMAccountName=" & UsernameToFind & "))" Using Results As SearchResultCollection = searcher.FindAll If Results Is Nothing OrElse Results.Count <> 0 Then Throw New ApplicationException("Invalid number of results returned - either no users were found or more than one user account was found") End If Using UserDE As DirectoryEntry = Results(0).GetDirectoryEntry Return CStr(UserDE.Properties("givenName").Value) & " " & CStr(UserDE.Properties("sn").Value) End Using End Using End Using End Function
If
Results.Count = 0
If Results Is Nothing OrElse Results.Count <> 0 Then
If Results Is Nothing OrElse Results.Count = 0 Then
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)