Article ID: 192436 - Last Review: July 15, 2004 - Revision: 3.2

How To Render the Global Address List with CDO

This article was previously published under Q192436

On This Page

Expand all | Collapse all

SUMMARY

This article contains sample code that uses Collaboration Data Objects (CDO) to render the Global Address List (GAL) to an Active Server Pages (ASP) page.

MORE INFORMATION

This is an example of how you can render the contents of the GAL to a Web browser using an ASP page script written with the Visual Basic Scripting Edition and CDO.

Copy and paste the following code to an ASP page. Modify the variables that set the server and mailbox to appropriate values. This code requires Microsoft Exchange Server version 5.5.

Sample Code

   <%@ LANGUAGE="VBSCRIPT" %>
   <HTML>
   <HEAD><TITLE>GAL Display</TITLE></HEAD>
   <BODY BGCOLOR=SILVER>
   <%

   'CONTAINER CONSTANT
   CONST CdoClassContainerRenderer  = 3

   'RENDERSTYLE CONSTANTS
   CONST CdoFolderContents  = 1
   CONST CdoFolderHierarchy = 2
   Dim objTableView
   Dim objColumn
   Dim objSession
   Dim objGAL
   Dim objALists
   Dim objCRenderer
   Dim objRenderApp
   strProfileInfo= "/o=<enterprise>/ou=<site>/cn=Configuration/cn=Servers/cn=<server name>" & vbLf & vblf & "anon"
' TODO: Replace <enterprise> with the name of your enterprise, and <site> with the name of your site.

   'Create a MAPI logon to the specified mailbox
   Set objSession= CreateObject("MAPI.Session")
   objSession.Logon , , False, True, 0, True, strProfileInfo

   Set objRenderApp = Server.CreateObject("AMHTML.application")
   Set objCRenderer =  _
   objRenderApp.CreateRenderer(CdoClassContainerRenderer)
   Set objALists = objSession.AddressLists
   Set objGAL = objALists.Item("Global Address List")
   objCRenderer.RowsPerPage = 100

   %>
   <DIV STYLE="background-color:GRAY"><FONT SIZE=4 COLOR=WHITE>
   Global Address List:</FONT></DIV>
   <%

   'Assign rendering object.
   objCRenderer.datasource = objGAL.AddressEntries

   'There are no default views associated with the
   'Global Address List (GAL), so a new one must be created.
   Set objTableView = objCRenderer.Views.Add("viewGAL")

   'Add a column in the table for each MAPI field you want to see and
   'give the HTML tags for how you would like each of them to be rendered.

   'Add Display name column.
    Set objColumn = objTableView.Columns.Add("Display Name", _
    "PR_Display_NAME" ,150, 8 ,1)
    objColumn.RenderUsing = "<B>%value%</B>"

   'Add phone column.
    Set objColumn = objTableView.Columns.Add("Phone", _
    "PR_BUSINESS_TELEPHONE_NUMBER" ,100, 8 ,2)
    objColumn.RenderUsing = "%value%"

   'Add office column.
    Set objColumn = objTableView.Columns.Add("Office", _
      "PR_OFFICE_LOCATION" ,100, 8 ,3)
    objColumn.RenderUsing = "%value%"

   'Add Title name column.
    Set objColumn = objTableView.Columns.Add("Title", "PR_TITLE", _
       100, 8 ,4)
    objColumn.RenderUsing = "<U>%value%</U>"

   'Add Company column.
    Set objColumn = objTableView.Columns.Add("Company", _
       "PR_COMPANY_NAME" ,100, 8 ,5)
    objColumn.RenderUsing = "%value%"

   'Add Alias column.
    Set objColumn = objTableView.Columns.Add("Alias", "PR_ACCOUNT", _
      100, 8 ,6)
    objColumn.RenderUsing = "%value%"

   'Make the view we created the current view used.
    objCRenderer.CurrentView=objTableView

   'Render the object.
    Response.write(objCRenderer.Render(CdoFolderContents))


   'Clean up Session & Rendering Objects.
    set objsession = nothing
    set objrenderapp = nothing
    set objCRenderer = nothing

   %>
   </BODY>
   </HTML>
				

REFERENCES

For information on how to acquire Collaboration Data Objects, please see the following article in the Microsoft Knowledge Base:
171440  (http://support.microsoft.com/kb/171440/EN-US/ ) INFO: Where to Acquire the Collaboration Data Objects Libraries
Microsoft Developer Network Library; search on: "CDO Rendering Library"

APPLIES TO
  • Microsoft Collaboration Data Objects 1.21
  • Microsoft Collaboration Data Objects 1.2
  • Microsoft Exchange Server 5.5 Standard Edition
Keywords: 
kbhowto kbmsg KB192436
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations