Specifying a Deep Traversal
Topic Last Modified: 2006-06-12
Deep traversals are not supported in MAPI stores, such as the client public store installed by Microsoft® Exchange Server 2007 , 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.
Example
VBScript
Example
'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