Platform SDK: Exchange 2000 Server

Navigating Folders

[This is preliminary documentation and subject to change.]

This Active Server Page example lists folders and items from a base URL as links on a Web page. A folder link lists its items and any subfolders using the same ASP file (navigate.asp). This code allows you to "drill down" through folders, subfolders and their items in the Web Store hierarchy.

An item link renders its content (render.asp). See the Displaying Items programming task for this code.

The value of the DAV:href property containing the URL of the seleted item or folder is passed as a parameter in an <A HREF> link. This value is either used for opening another recordset if it is a folder, or opening a record to display its content if it is an item.

This example also demonstrates investigating schema values and using content-class to display the appropriate icons for items and folders.

[VBScript]
'*************************************************
'Save this code as Navigate.ASP
'*************************************************

Dim Rec
Dim strURL
Dim strQ
Dim Rs
Dim strHREF

Dim DomainName
Dim strLocalPath

' set your own values to these variables:
DomainName = "microsoft.com"
strLocalPath = "public folders"

Set Rec = CreateObject("ADODB.Record")
Set Rs = CreateObject("ADODB.Recordset")

'If this is the first time to the page, there is
'no QueryString value, so the base URL is opened
'specifed by the strLocalPath variable. Otherwise,
'the DAV:href value is URL to use
If IsEmpty(Request.QueryString("f")) Then
   strURL = "file://./backofficestorage/" & DomainName & "/" & strLocalPath
   Rec.Open strURL
else
   strURL = Request.QueryString("f")
   Rec.Open strURL
End If

'create the SQL query for the recordset
strQ = "select "
strQ = strQ & " ""urn:schemas:mailheader:content-class"""
strQ = strQ & ", ""DAV:isfolder"""
strQ = strQ & ", ""DAV:id"""
strQ = strQ & ", ""DAV:hassubs"""
strQ = strQ & ", ""DAV:href"""
strQ = strQ & ", ""DAV:displayname"""
strQ = strQ & " from scope ('shallow traversal of " & Chr(34)
strQ = strQ & strURL & """') "
strQ = strQ & " WHERE ""DAV:ishidden"" = false"

'open the recordset, a list of folder and/or items
Rs.Open strQ, Rec.ActiveConnection


'create a table for the list
'the first col has no heading and is for icons
'the second col is the DAV:displayname value
'the third col denotes subfolders
Response.Write "<FONT FACE=ARIAL SIZE=2>"
Response.Write "<table cellpadding=5><tr><th></th><th>Item</th><th>Sub Folders</th></tr>"

If Not Rs.EOF Then
   Rs.MoveFirst
End If

While Not Rs.EOF
   'As the recordset is enumerated,
   'write values to the table
   'and prepare the DAV:href value with URLPathEncode
   strHREF = Server.URLPathEncode(Rs.Fields("DAV:href"))
   Response.Write "<TR>"
   Response.Write "<TD><IMG SRC="

   'display an appropriate icon for the content-class
   Select Case Rs.Fields("urn:schemas:mailheader:content-class").Value
      Case "urn:content-classes:calendarfolder"
         Response.Write "CALENDAR.GIF"
      Case "urn:content-classes:appointment"
         Response.Write "APPOINTMENT.GIF"
      Case "urn:content-classes:taskfolder"
         Response.Write "TASK.GIF"
      Case "urn:content-classes:task"
         Response.Write "TASK.GIF"
      Case "urn:content-classes:mailfolder"
         Response.Write "PUBLIC_FOLDER.GIF"
      Case "urn:content-classes:folder"
         Response.Write "PUBLIC_FOLDER.GIF"
      Case "urn:content-classes:document"
         Response.Write "WORDICON.GIF"
      Case Else
         Response.Write "READ.GIF"
   End Select


   Response.Write "></TD>"
   Response.Write "<TD><FONT FACE=ARIAL SIZE=1>"

   'format the DAV:displayname value as the link text
   'and link back to navigate.asp if the link is a folder or
   'link to render.asp to render content, using the DAV:href
   'value as a parameter (f) to be picked up by Response.QueryString
   Response.Write "<A HREF="

   If Rs.Fields("DAV:isfolder").Value = True Then
      Response.Write Chr(34) & "navigate.asp?f=" & strHREF & Chr(34) & ">"
   else
      Response.Write Chr(34) & "render.asp?f=" & strHREF & Chr(34) & ">"
   end if

   Response.Write Rs.Fields("DAV:displayname").Value & "</A></TD>"
   Response.Write "<TD>"

   if Rs.Fields("DAV:hassubs").Value = True Then
      Response.Write "<IMG SRC=ACCEPT.GIF></TD>"
   else
      Response.Write "</TD>"
   end if

   Response.Write "</TR>"
   Rs.MoveNext
Wend

Response.Write "</table>"