HOWTO: Render a Folder To an ASP Page with CDO

ID: Q192435


The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.2, 1.21
  • Collaboration Data Objects Rendering Library, version 1.2


SUMMARY

This article contains sample code that used Collaboration Data Objects (CDO) to render the messages in the Sent Items folder to an Active Server Pages (ASP) page.


MORE INFORMATION

This is an example of how you can render the contents of a Messaging Application Programming Interface (MAPI) folder to a Web browser using an ASP page script written in 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>Sent Items Display</TITLE></HEAD>
   <BODY BGCOLOR=SILVER>
   <%

   'CONTAINER CONSTANT
    CONST CdoClassContainerRenderer  = 3
    CONST CdoClassObjectRenderer  = 2

   'RENDERSTYLE CONSTANTS
    CONST CdoFolderContents = 1
    CONST CdoFolderHierarchy = 2

   '===== Default Folder Constants ========
   'These constants are passed into the Session.GetDefaultFolder()
   'method to return their respective folders.

    CONST CdoDefaultFolderCalendar = 0
    CONST CdoDefaultFolderInbox = 1
    CONST CdoDefaultFolderOutbox = 2
    CONST CdoDefaultFolderSentItems = 3
    CONST CdoDefaultFolderDeletedItems = 4
    CONST CdoDefaultFolderContacts = 5
    CONST CdoDefaultFolderJournal = 6
    CONST CdoDefaultFolderNotes = 7
    CONST CdoDefaultFolderTasks = 8
    CONST CdoDefaultFolderTotal = 9
   '===================================

   strProfileInfo= "<valid server>" & vbLf & "<valid mailbox>"

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

   ' Create a container rendering application.
     Set objRenderApp = Server.CreateObject("AMHTML.application")
     Set objCRenderer = _
       objRenderApp.CreateRenderer(CdoClassContainerRenderer)


   'There are two ways to format data with a CDO Rendering application:
   ' 1 - By setting a format to a field of the message and rendering
   '     that field a certain way depending on the value of the
   '     information.
   ' 2 - Render a column of data all in the same fashion.

   ' format importance field
     Set cFormat = objCRenderer.Formats.Add("PR_Importance")


   ' The images below must exist on the server where the script is located.
     Set cPattern = cFormat.Patterns.Add(0,"<img src=low.gif>")
     Set cPattern = cFormat.Patterns.Add(1,"<img src=invisibl.gif>")
     Set cPattern = cFormat.Patterns.Add(2,"<img src=urgent.gif>")

   ' Format Class field.
     Set cFormat = objCRenderer.Formats.Add("PR_Message_Class")
     Set cPattern = cFormat.Patterns.Add("IPM.Note", _
          "<img src=newmail.gif>")
     Set cPattern = cFormat.Patterns.Add("IPM.AppointmentItem", _
          "<img src=newappt.gif>")
     Set cPattern = cFormat.Patterns.Add("IPM.Post","<img src=post.gif>")
     Set cPattern = cFormat.Patterns.Add("IPM.Contact", _
          "<img src=meeting.gif>")

   ' Format Attachment field.
     Set cFormat = objCRenderer.Formats.Add("PR_HASATTACH")
     Set cPattern = cFormat.Patterns.Add(0,"<img src=invisibl.gif>")
     Set cPattern = cFormat.Patterns.Add(1,"<img src=papclip.gif>")

   ' Set the datasource to the appropriate folder.
   ' This will set the container to be rendered to the Sent items folder
     objCRenderer.DataSource= _
       objSession.GetDefaultFolder(CdoDefaultFolderSentItems).Messages


   ' Use the default predefined view.
     Set objTableView = objCRenderer.Views(1)

   ' Add body column and render it in blue.
   '   set objColumn =  _
   ' objTableView.Columns.Add("Body", "PR_Body" ,150, 8 ,8)

   '   objColumn.RenderUsing = "<font color=blue>%value%</font>"

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

Keywords : kbASP kbCDO120 kbCDO121 kbMsg kbGrpMsg
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbhowto


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