Specifying a Deep Traversal

Specifying a Deep Traversal

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Deep traversals are not supported in MAPI stores, such as the client public store installed by Microsoft® Exchange Server 2003, but are supported in private stores and in any new public folder tree. Because deep traversals open every item in the store, they should be used sparingly to reduce server workload. See Search Scope for information on deep traversals. The results of the search in this example are passed to the DoResults function in Enumerating Search Results.

VBScript

'Finds items from a sender, searching subfolders
'Passes search result recordset to DoResults (see Enumerating Results)

On Error GoTo ErrHandler

Const adErrNoCurrentRecord = 3021
Dim Conn
Dim info
Dim infoNT
Dim cName
Dim dName
Dim cURL
Dim relURL
Dim strQ
Dim Rs

'get computer and domain information
Set info   = CreateObject("ADSystemInfo")
Set infoNT = CreateObject("WinNTSystemInfo")
cName = infoNT.ComputerName
dName = info.DomainDNSName

'create connection object
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Exoledb.DataSource"

'URL for connection object
'is at the virtual directory root
cURL = "http://" & cName & "." & dName & "/" & "public"

Conn.Open cURL

'relative URL is the folder to search
relURL = "Reports"

sender = "Jane Clayton"

Set Rs = CreateObject("ADODB.Recordset")

'construct the SQL query, note the scope for deep traversal
strQ = "SELECT ""urn:httpmail:subject"" "
strQ = strQ & "FROM scope('deep traversal of """ & strURL & """ ')"
strQ = strQ & "WHERE ""urn:schemas:httpmail:sendername"" = '" & sender & "'"

Rs.Open strQ, Conn

'If empty recordset, return error
'If successful call DoResults routine passing the recorset
If Rs.EOF = True Then
   Response.Write "No items found, run another query."
Else
   Response.Write "Success! Found " & Rs.RecordCount
   DoResults Rs
End If

GoTo Ending

' Implement custom error handling here.
ErrHandler:
   WScript.echo Err.Number + " " + Err.Description
   Err.Clear

Ending:
   ' Clean up.
   Conn.Close
   Rs.Close

   Set Conn = Nothing
   Set Rs = Nothing

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.