Dim RootDSE As New DirectoryServices.DirectoryEntry("ldap://rootDSE")
Dim DomainDistinguishedName As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDistinguishedName)
Dim ADSearch As New DirectorySearcher(ADEntry)
Dim FullName As String
Dim Title As String
Dim OtherTelephone As String
Dim Telephone_Number As String
Dim Extension As String
Dim sAMAccountName As String
Dim mobile As String
Dim department As String
Dim ADSearchResult As System.DirectoryServices.SearchResult
Dim mySearchOption As New DirectoryServices.SortOption
Dim j As Integer
OtherTelephone = ""
'ADSearch.Filter = "(&(objectClass=user)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2)" & "))"
ADSearch.Filter = "(&(objectClass=user)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2))"
ADSearch.SearchScope = SearchScope.Subtree
ADSearch.PropertiesToLoad.Add("cn")
ADSearch.PropertiesToLoad.Add("otherTelephone")
ADSearch.PropertiesToLoad.Add("title")
ADSearch.PropertiesToLoad.Add("telephoneNumber")
ADSearch.PropertiesToLoad.Add("sAMAccountName")
ADSearch.PropertiesToLoad.Add("mobile")
'ADSearch.PropertiesToLoad.Add("department")
'Sorting by the names
mySearchOption.Direction = DirectoryServices.SortDirection.Ascending
mySearchOption.PropertyName = "cn"
ADSearch.Sort = mySearchOption
Literal1.Text = ""
On Error Resume Next
For Each ADSearchResult In ADSearch.FindAll()
FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString()
Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString()
Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value
Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1)
sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca"
If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then
mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString()
End If
Literal1.Text = Literal1.Text.Trim() & "<p><b>" & FullName.Trim() & "</b><br />" & Title & "<br /> " & _
"Phone/Email :x" & Extension & "/ <a href=""mailto://" & sAMAccountName & """>" & sAMAccountName & "</a>" & _
"<br /> DID " & Telephone_Number
Next
On Error GoTo 0
Dim CellString As String
On Error Resume Next
For Each ADSearchResult In ADSearch.FindAll()
FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString()
Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString()
Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value
Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1)
sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca"
If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then
mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString()
End If
If i = 1 Then
CellString = "<tr><td>" & FullName & "<br />" & Title.ToString() & _
Telephone_Number .ToString() & "</td>"
End If
If i > 1 Then
CellString = CellString &<tr><td>" & FullName & "<br />" & Title.ToString() & _
Telephone_Number .ToString() & "</td>" & "</tr>"
End If
loop
CellString = "<table border=1>" & CellString & "</table>"
Response.Write(CellString)
However, I get two problems here
1. When I see the display, my search input box and search button vanished. How to keep them top and display results below?
Thank you guys for not giving any single input on this....You all are great
After several tries, I managed to write and got what I want.. Below is the FULL code that displays the records in tabular form using HTML table. I will be happy If this code helps anyone
Dim k as integer
Dim FullName As String
Dim Title As String
Dim OtherTelephone As String
Dim Telephone_Number As String
Dim Extension As String
Dim sAMAccountName As String
Dim mobile As String
Dim department As String
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://rootDSE")
Dim DomainDistinguishedName As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDistinguishedName)
Dim ADSearch As New DirectorySearcher(ADEntry)
dim CellString as new stringbuilde
ADSearch.PropertiesToLoad.Add("cn")
ADSearch.PropertiesToLoad.Add("otherTelephone")
ADSearch.PropertiesToLoad.Add("title")
ADSearch.PropertiesToLoad.Add("telephoneNumber")
ADSearch.PropertiesToLoad.Add("sAMAccountName")
ADSearch.PropertiesToLoad.Add("mobile")
ADSearch.PropertiesToLoad.Add("department")
ADSearch.PropertiesToLoad.Add("sn")
ADSearch.PropertiesToLoad.Add("givenName")
'Sorting by the names
mySearchOption.Direction = DirectoryServices.SortDirection.Ascending 'Sort Ascending
mySearchOption.PropertyName = "cn" 'Write the name of the property here
ADSearch.Sort = mySearchOption
CellString.Append("<table height=200 border=1>")
For Each ADSearchResult In ADSearch.FindAll()
FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString()
Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString()
Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value
Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1)
sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca"
lastName = ADSearchResult.GetDirectoryEntry().Properties.Item("sn").Value.ToString().Trim()
strFirstName = ADSearchResult.GetDirectoryEntry().Properties.Item("givenName").Value.ToString().Trim()
If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then
mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString()
End If
If k = 1 Then
CellString.Append("<tr>")
End If
If (Title <> "") And (lastName <> "") Then
CellString.Append("<td>" & "<P><b>" & FullName & "</b><br />" & Title & "<br />")
CellString.Append("Phone/Email :x" & Extension & "/ <a href=""mailto://" & sAMAccountName & """>" & sAMAccountName & "</a>")
CellString.Append("<br /> DID :" & Telephone_Number)
CellString.Append("</td>")
k = k + 1
End If
If (k = 4) Then
CellString.Append("</tr>")
k = 1
End If
FullName = ""
Title = ""
Telephone_Number = ""
Extension = ""
sAMAccountName = ""
department = ""
lastName = ""
Next
CellString.Append("</table>")
mystr = CellString.ToString()
Third.InnerHtml = mystr
LDAPActive DirectoryHTML
Marked as answer by Raj10 on May 14, 2010 08:23 PM
Raj10
Member
10 Points
25 Posts
Active Directory Records Showing in Tabular format
May 12, 2010 10:41 PM|LINK
Dim RootDSE As New DirectoryServices.DirectoryEntry("ldap://rootDSE") Dim DomainDistinguishedName As String = RootDSE.Properties("DefaultNamingContext").Value Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDistinguishedName) Dim ADSearch As New DirectorySearcher(ADEntry) Dim FullName As String Dim Title As String Dim OtherTelephone As String Dim Telephone_Number As String Dim Extension As String Dim sAMAccountName As String Dim mobile As String Dim department As String Dim ADSearchResult As System.DirectoryServices.SearchResult Dim mySearchOption As New DirectoryServices.SortOption Dim j As Integer OtherTelephone = "" 'ADSearch.Filter = "(&(objectClass=user)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2)" & "))" ADSearch.Filter = "(&(objectClass=user)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2))" ADSearch.SearchScope = SearchScope.Subtree ADSearch.PropertiesToLoad.Add("cn") ADSearch.PropertiesToLoad.Add("otherTelephone") ADSearch.PropertiesToLoad.Add("title") ADSearch.PropertiesToLoad.Add("telephoneNumber") ADSearch.PropertiesToLoad.Add("sAMAccountName") ADSearch.PropertiesToLoad.Add("mobile") 'ADSearch.PropertiesToLoad.Add("department") 'Sorting by the names mySearchOption.Direction = DirectoryServices.SortDirection.Ascending mySearchOption.PropertyName = "cn" ADSearch.Sort = mySearchOption Literal1.Text = "" On Error Resume Next For Each ADSearchResult In ADSearch.FindAll() FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString() Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString() Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1) sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca" If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString() End If Literal1.Text = Literal1.Text.Trim() & "<p><b>" & FullName.Trim() & "</b><br />" & Title & "<br /> " & _ "Phone/Email :x" & Extension & "/ <a href=""mailto://" & sAMAccountName & """>" & sAMAccountName & "</a>" & _ "<br /> DID " & Telephone_Number Next On Error GoTo 0html active direcotry
Raj10
Member
10 Points
25 Posts
Re: Active Directory Records Showing in Tabular format
May 13, 2010 12:04 AM|LINK
I further tried as following
Dim CellString As String On Error Resume Next For Each ADSearchResult In ADSearch.FindAll() FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString() Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString() Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1) sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca" If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString() End If If i = 1 Then CellString = "<tr><td>" & FullName & "<br />" & Title.ToString() & _ Telephone_Number .ToString() & "</td>" End If If i > 1 Then CellString = CellString &<tr><td>" & FullName & "<br />" & Title.ToString() & _ Telephone_Number .ToString() & "</td>" & "</tr>" End If loop CellString = "<table border=1>" & CellString & "</table>" Response.Write(CellString)However, I get two problems here
1. When I see the display, my search input box and search button vanished. How to keep them top and display results below?
2. Table is not coming properly
Raj10
Member
10 Points
25 Posts
Re: Active Directory Records Showing in Tabular format
May 13, 2010 01:16 PM|LINK
Any help on this please?
Raj10
Member
10 Points
25 Posts
Re: Active Directory Records Showing in Tabular format
May 14, 2010 05:34 PM|LINK
Thank you guys for not giving any single input on this....You all are great
After several tries, I managed to write and got what I want.. Below is the FULL code that displays the records in tabular form using HTML table. I will be happy If this code helps anyone
Dim k as integer Dim FullName As String Dim Title As String Dim OtherTelephone As String Dim Telephone_Number As String Dim Extension As String Dim sAMAccountName As String Dim mobile As String Dim department As String Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://rootDSE") Dim DomainDistinguishedName As String = RootDSE.Properties("DefaultNamingContext").Value Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDistinguishedName) Dim ADSearch As New DirectorySearcher(ADEntry) dim CellString as new stringbuilde ADSearch.PropertiesToLoad.Add("cn") ADSearch.PropertiesToLoad.Add("otherTelephone") ADSearch.PropertiesToLoad.Add("title") ADSearch.PropertiesToLoad.Add("telephoneNumber") ADSearch.PropertiesToLoad.Add("sAMAccountName") ADSearch.PropertiesToLoad.Add("mobile") ADSearch.PropertiesToLoad.Add("department") ADSearch.PropertiesToLoad.Add("sn") ADSearch.PropertiesToLoad.Add("givenName") 'Sorting by the names mySearchOption.Direction = DirectoryServices.SortDirection.Ascending 'Sort Ascending mySearchOption.PropertyName = "cn" 'Write the name of the property here ADSearch.Sort = mySearchOption CellString.Append("<table height=200 border=1>") For Each ADSearchResult In ADSearch.FindAll() FullName = ADSearchResult.GetDirectoryEntry().Properties.Item("cn").Value.ToString() Title = ADSearchResult.GetDirectoryEntry().Properties.Item("title").Value.ToString() Telephone_Number = ADSearchResult.GetDirectoryEntry().Properties.Item("telephoneNumber").Value Extension = ADSearchResult.GetDirectoryEntry().Properties.Item("otherTelephone").Value(1) sAMAccountName = ADSearchResult.GetDirectoryEntry().Properties.Item("sAMAccountName").Value.ToString() & "@resound.ca" lastName = ADSearchResult.GetDirectoryEntry().Properties.Item("sn").Value.ToString().Trim() strFirstName = ADSearchResult.GetDirectoryEntry().Properties.Item("givenName").Value.ToString().Trim() If Not IsDBNull(ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value) Then mobile = ADSearchResult.GetDirectoryEntry().Properties.Item("mobile").Value.ToString() End If If k = 1 Then CellString.Append("<tr>") End If If (Title <> "") And (lastName <> "") Then CellString.Append("<td>" & "<P><b>" & FullName & "</b><br />" & Title & "<br />") CellString.Append("Phone/Email :x" & Extension & "/ <a href=""mailto://" & sAMAccountName & """>" & sAMAccountName & "</a>") CellString.Append("<br /> DID :" & Telephone_Number) CellString.Append("</td>") k = k + 1 End If If (k = 4) Then CellString.Append("</tr>") k = 1 End If FullName = "" Title = "" Telephone_Number = "" Extension = "" sAMAccountName = "" department = "" lastName = "" Next CellString.Append("</table>") mystr = CellString.ToString() Third.InnerHtml = mystrLDAP Active Directory HTML