I use the following asp code to return staff details from AD to create a searchable web based address book. It works well but the results are displayed in a random order. could one of you code gurus please provide the code to sort the results alphabetically?
many thanks. Greg.
'********************************************************
' function: find a user in Exchange
' author: Christian Kiefer
' email: christian.kiefer@bsp.de
'********************************************************
'*** you only have to change this variable:
'*** the rest will work automaticly
strServerName = "Exchange01"
'******************************************
bolSearch = false
strLastname = Request("lastname")
strName = Request("name")
if strName<>"" or strLastname<>"" then
bolSearch = true
end if
%>
<HTML>
<head>
<title>Suche Exchange</title>
<style>
<!--
BODY {font-family:Arial,Helvetica; font-size:10pt;}
TD {font-family:Arial,Helvetica; font-size:9pt;}
//-->
</style>
</head>
<BODY>
<CENTER><H3>Search in Exchange</H3><CENTER>
<%
set oConn = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")
oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"
set oCommand.ActiveConnection = oConn
if bolSearch then
'***put query string together
strQuery = "<LDAP://" & strServername & ">;(&(objectClass=*)(sn=" & strLastname & "*)(givenname=" & strName & "*));sn, department, givenname,cn,telephoneNumber,mail;subtree"
oCommand.CommandText = strQuery
set oRS = oCommand.Execute
'***display table only if hits or search criteria are given
if bolSearch and not oRS.eof then
%>
<div align="center">
<table cellpadding="0" border="0" cellspacing="0">
<tr bgcolor="#C0C0C0">
<td height="20"><b>Name </b></td>
<td height="20"><b>Department </b></td>
<td height="20"><b>Telefon </b></td>
<td height="20"><b>Email </b></td>
</tr>
<%While not ors.eof%>
<tr>
<td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%> </td>
<td><%=oRS.Fields("department")%> </td>
<td><%=oRS.Fields("telephoneNumber")%> </td>
<td><a href="mailto:<%=oRS.Fields("mail")%>"><%=oRS.Fields("mail")%> </A></td>
</tr>
<%
oRS.MoveNext
wend %>
<tr bgcolor="#C0C0C0">
<td colspan="4" height="20"> </td>
</tr>
</table>
</div>
<%
else
Response.Write "No entry found"
end if
end if
%>
<br>
<br>
<form method="post" action="search_exchange.asp">
<table border="0" cellpadding="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" >
<tr>
<td colspan="5" bgcolor="#C0C0C0" height="20"><b> Search</b></td>
</tr>
<tr>
<td><b>Lastname </b></td>
<td valign="top"><input type="text" name="lastname" value="<%=strLastname%>" size="20"></td>
<td><span lang="de"><b> </b></span></td>
<td><b>N</b><span lang="de"><b>ame</b></span></td>
<td valign="top">
<p align="center">
<input type="text" name="name" value="<%=strName%>" size="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Search" name="start search"></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
many thanks. Greg.
'********************************************************
' function: find a user in Exchange
' author: Christian Kiefer
' email: christian.kiefer@bsp.de
'********************************************************
'*** you only have to change this variable:
'*** the rest will work automaticly
strServerName = "Exchange01"
'******************************************
bolSearch = false
strLastname = Request("lastname")
strName = Request("name")
if strName<>"" or strLastname<>"" then
bolSearch = true
end if
%>
<HTML>
<head>
<title>Suche Exchange</title>
<style>
<!--
BODY {font-family:Arial,Helvetica; font-size:10pt;}
TD {font-family:Arial,Helvetica; font-size:9pt;}
//-->
</style>
</head>
<BODY>
<CENTER><H3>Search in Exchange</H3><CENTER>
<%
set oConn = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")
oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"
set oCommand.ActiveConnection = oConn
if bolSearch then
'***put query string together
strQuery = "<LDAP://" & strServername & ">;(&(objectClass=*)(sn=" & strLastname & "*)(givenname=" & strName & "*));sn, department, givenname,cn,telephoneNumber,mail;subtree"
oCommand.CommandText = strQuery
set oRS = oCommand.Execute
'***display table only if hits or search criteria are given
if bolSearch and not oRS.eof then
%>
<div align="center">
<table cellpadding="0" border="0" cellspacing="0">
<tr bgcolor="#C0C0C0">
<td height="20"><b>Name </b></td>
<td height="20"><b>Department </b></td>
<td height="20"><b>Telefon </b></td>
<td height="20"><b>Email </b></td>
</tr>
<%While not ors.eof%>
<tr>
<td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%> </td>
<td><%=oRS.Fields("department")%> </td>
<td><%=oRS.Fields("telephoneNumber")%> </td>
<td><a href="mailto:<%=oRS.Fields("mail")%>"><%=oRS.Fields("mail")%> </A></td>
</tr>
<%
oRS.MoveNext
wend %>
<tr bgcolor="#C0C0C0">
<td colspan="4" height="20"> </td>
</tr>
</table>
</div>
<%
else
Response.Write "No entry found"
end if
end if
%>
<br>
<br>
<form method="post" action="search_exchange.asp">
<table border="0" cellpadding="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" >
<tr>
<td colspan="5" bgcolor="#C0C0C0" height="20"><b> Search</b></td>
</tr>
<tr>
<td><b>Lastname </b></td>
<td valign="top"><input type="text" name="lastname" value="<%=strLastname%>" size="20"></td>
<td><span lang="de"><b> </b></span></td>
<td><b>N</b><span lang="de"><b>ame</b></span></td>
<td valign="top">
<p align="center">
<input type="text" name="name" value="<%=strName%>" size="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Search" name="start search"></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>