Microsoft KB Archive/291171

= How To List Public Folders by Using WebDAV =

Article ID: 291171

Article Last Modified on 5/9/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Parser 2.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q291171



SUMMARY
This article demonstrates how to list all the folders of a folder hierarchy by using Web Distributed Authoring and Versioning (WebDAV).



MORE INFORMATION
To list all of the folders in the public folder hierarchy, follow these steps:  In Microsoft Visual Basic, create a Standard EXE project. Form1 is created by default. Add a command button to Form1 and name the button Command1. Add a reference to the MSXML object library.  Paste the following code in the code section of Form1.NOTE: Change e2kServer in the code to the name of your Exchange server. Private Sub Command1_Click Dim strURL As String Dim sUserID As String Dim sPassword As String strURL = &quot;http://e2KServer/public/&quot; sUserID = &quot;UserID&quot; 'TODO sPassword = &quot;password&quot; 'TODO ListFolders strURL, sUserID, sPassword End Sub

Sub ListFolders(ByVal strURL As String, ByVal sUserID As String, _ ByVal sPassword As String) Dim oDoc As MSXML.DOMDocument Dim oDocBack As MSXML.DOMDocument

Dim oNode As IXMLDOMElement Dim oNode2 As IXMLDOMElement Dim req As MSXML.XMLHTTPRequest

Set oDoc = CreateObject(&quot;MICROSOFT.XMLDOM&quot;) Set oDocBack = CreateObject(&quot;MICROSOFT.XMLDOM&quot;) MSXML 4.0 Dim oDoc As MSXML2.DOMDocument40 Dim oDocBack As MSXML2.DOMDocument40 Dim req As MSXML2.XMLHTTP40 Set oDoc = CreateObject(&quot;MSXML2.DomDocument.4.0&quot;) Set oDocBack = CreateObject(&quot;MSXML2.DomDocument.4.0&quot;) Set pi = oDoc.createProcessingInstruction(&quot;xml&quot;, &quot;version=&quot;&quot;1.0&quot;&quot;&quot;) oDoc.appendChild pi

Set oNode = oDoc.createNode(1, &quot;searchrequest&quot;, &quot;DAV:&quot;) Set oDoc.documentElement = oNode

Set oNode2 = oDoc.createNode(1, &quot;sql&quot;, &quot;DAV:&quot;) oNode.appendChild oNode2 strQuery = &quot;Select &quot;&quot;DAV:displayname&quot;&quot; From &quot; strQuery = strQuery & &quot;Scope('Shallow Traversal of &quot;&quot;&quot; & strURL & &quot;&quot;&quot;')&quot; Set query = oDoc.createTextNode(strQuery) oNode2.appendChild query

Set req = CreateObject(&quot;microsoft.xmlhttp&quot;) req.open &quot;SEARCH&quot;, strURL, False, sUserID, sPassword req.setRequestHeader &quot;Translate&quot;, &quot;f&quot; req.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot; req.setRequestHeader &quot;Depth&quot;, &quot;0&quot; req.send oDoc

Set oDocBack = req.responseXML

Dim objNodeList

'Typically the DAV namespace get the 'a' prefix. 'If you are specifying multiple properties in a search, examine the 'returned XML beforehand to determine prefixes for your code.

Set objNodeList = oDocBack.getElementsByTagName(&quot;a:displayname&quot;) For i = 0 To (objNodeList.length - 1) Set objNode = objNodeList.nextNode Debug.Print objNode.Text Next End Sub  Run the project.

