HOWTO: Render the Global Address List with CDO

ID: Q192436


The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.2, 1.21
  • Microsoft Exchange Server, version 5.5


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"

   '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")

   %>
   <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:

Q171440 INFO: Where to Acquire the Collaboration Data Objects Libraries
Microsoft Developer Network Library; search on: "CDO Rendering Library"

Additional query words: Render GAL ASP CDO

Keywords : kbASP kbCDO120 kbCDO121 kbXchge550 kbMsg kbVBScript kbGrpMsg
Version : WINDOWS:1.2,1.21; winnt:5.5
Platform : WINDOWS winnt
Issue type : kbhowto


Last Reviewed: December 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.