Howto: WebDAV SEARCH with range headers using VBScript
'The example below demonstrates how to do a WebDAV SEARCH with range headers.
Public Function GetItemListXML(sHREF, sUserName, sPassword, sDepth)
Dim sQuery ' As String
Dim sText 'As String
sQuery = "<?xml version='1.0'?>" & _
"<g:searchrequest xmlns:g='DAV:'>" & _
"<g:sql>SELECT ""DAV:displayname"", " & _
"""DAV:href"" " & _
"FROM SCOPE('SHALLOW TRAVERSAL OF """ & sHREF & """')" & _
" WHERE ""DAV:isfolder"" = false AND ""DAV:ishidden"" = false" & _
"</g:sql>" & _
"</g:searchrequest>"
sText = DoDavRequest("SEARCH", sQuery, sHREF, sUserName, sPassword, sDepth)
GetItemListXML = sText
End Function
Public Function DoDavRequest(sType, sQuery, sHREF, sUserName, sPassword, sDepth)
Dim HttpWebRequest 'As MSXML2.XMLHTTP30
Set HttpWebRequest = CreateObject("microsoft.xmlhttp") ' = New MSXML2.XMLHTTP30
Dim sText 'As String
' Open the folder
HttpWebRequest.open sType, sHREF, False, sUserName, sPassword
' Set up request headers
HttpWebRequest.setRequestHeader "Content-Type", "text/xml"
HttpWebRequest.setRequestHeader "Depth", "0"
HttpWebRequest.setRequestHeader "Range", sDepth
'HttpWebRequest.setRequestHeader "Range", "rows=10-20,40-50" ' Example of multiple ranges
' Send the query
HttpWebRequest.send (sQuery)
sText = HttpWebRequest.ResponseText
Set HttpWebRequest = Nothing
DoDavRequest = sText
End Function
Dim sHREF
Dim sUserName
Dim sPassword
Dim sRet
sUserName = "Administrator" ' TODO: change
sPassword = "test" ' TODO: change
sHREF = "https://myexserver/exchange/administrator/inbox" ' TODO: change
sDepth = "rows=0-3"
sRet = GetItemListXML(sHREF, sUserName, sPassword, sDepth)
wscript.echo sRet
sDepth = "rows=4-7"
sRet = GetItemListXML(sHREF, sUserName, sPassword, sDepth)
wscript.echo sRet