Click here to Skip to main content
13,735,232 members
Click here to Skip to main content
Articles » Web Development » ASP » Howto » Downloads


45 bookmarked
Posted 10 May 2004

User search in the address book of the Exchange Server, with ASP and ADSI / LDAP

, 31 Oct 2004
User search in the address book of the Exchange Server with ASP and ADSI / LDAP.
' function:	find a user in Exchange
' author:	Christian Kiefer
' email:

'*** 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

<title>Suche Exchange</title>
BODY {font-family:Arial,Helvetica; font-size:10pt;}
TD {font-family:Arial,Helvetica; font-size:9pt;}
<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&nbsp;</b></td>
    	  <td height="20"><b>Department&nbsp;</b></td>
	      <td height="20"><b>Telefon&nbsp;</b></td>
    	  <td height="20"><b>Email&nbsp;</b></td>
    	<%While not ors.eof%>
    		<td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%>&nbsp;</td>
    	  	<td><a href="mailto:<%=oRS.Fields("mail")%>"><%=oRS.Fields("mail")%>&nbsp;</A></td>
	   wend %>
    	<tr bgcolor="#C0C0C0">
	      <td colspan="4" height="20">&nbsp;</td>
		Response.Write "No entry found"
	end if
end if

<form method="post" action="search_exchange.asp">
<table border="0" cellpadding="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" >
    <td colspan="5" bgcolor="#C0C0C0" height="20"><b>&nbsp;Search</b></td>
    <td valign="top"><input type="text" name="lastname" value="<%=strLastname%>" size="20"></td>
    <td><span lang="de"><b>&nbsp;&nbsp;</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>
    <td><input type="submit" value="Search" name="start search"></td>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Christian Kiefer
Web Developer
Germany Germany
Christian Kiefer works as a Consultant and developer for internet-software in the middle of Germany.

As an Internet specialist, Christian has designed and developed many ASP based applications that take advantage of advanced database and directory services.

Christian specializes in advanced Internet technologies such as DHTML, ASP, ADSI, XML, and ASP.NET.

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180920.1 | Last Updated 1 Nov 2004
Article Copyright 2004 by Christian Kiefer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid