How to retrieve all the items in a public folder on a computer that is running Exchange 2000 (314180)



The information in this article applies to:

  • Microsoft Exchange 2000 Server
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic .NET (2003)
  • Microsoft XML 3.0
  • Microsoft XML 4.0

This article was previously published under Q314180

SUMMARY

This article describes how to use Microsoft XML 3.0 and Microsoft Visual Basic .NET to retrieve all the items, not including the folders, from a public folder on a computer that is running Microsoft Exchange 2000 Server.

MORE INFORMATION

To retrieve all the items from a public folder on a computer that is running Exchange 2000, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the Visual Basic Projects types list, click Console Application.

    By default, the Module1.vb file is created.
  4. Add a reference to Microsoft XML 3.0. To do so, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab, locate Microsoft XML v3.0, and then click Select.
    3. In the Add References dialog box, click OK.
    4. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
  5. In the code window, replace the code with the following:
    Module Module1
    
        Sub Main()
            Dim oXMLHttp As MSXML2.XMLHTTP30 = New MSXML2.XMLHTTP30()
            Dim sUrl As String
            Dim sQuery As String
    
            ' TODO: Replace with your folder URL
            sUrl = "http://ExchSrvr/public/MyFolder/MySubFolder"
    
            ' TODO: Replace the domain name, the user name, and the password with your actual
            ' domain name, user name, and password.
            oXMLHttp.open("SEARCH", sUrl, False, "domain\username", "password")
    
            ' Find items with Subject = 'Test'
            sQuery = "<?xml version='1.0'?>" & _
                     "<g:searchrequest xmlns:g='DAV:'>" & _
                     "<g:sql>SELECT ""DAV:displayname"" " & _
                     "FROM SCOPE('SHALLOW TRAVERSAL OF """ & sUrl & """') " & _
                     "WHERE ""urn:schemas:mailheader:subject"" = 'Test'" & _
                     "</g:sql>" & _
                     "</g:searchrequest>"
    
            ' Set the request headers.
            oXMLHttp.setRequestHeader("Content-Type", "text/xml")
            oXMLHttp.setRequestHeader("Translate", "f")
            oXMLHttp.setRequestHeader("Depth", "0")
            oXMLHttp.setRequestHeader("Content-Length", "" & sQuery.Length)
    
            ' Send the request.
            oXMLHttp.send(sQuery)
    
            ' Output the response.
            Console.WriteLine(oXMLHttp.status)
            Console.WriteLine(oXMLHttp.statusText)
            Console.WriteLine(oXMLHttp.responseText)
    
            ' Clean up
            oXMLHttp = Nothing
        End Sub
    
    End Module
    					
  6. Search for TODO in the code, and then modify the code for your environment.
  7. Press F5 to build and to run the program.
  8. Make sure that the DisplayName property of the items in the folder was received.

REFERENCES

For information about the WebDAV protocol, visit the following MSDN Web site:

Modification Type:MinorLast Reviewed:7/21/2004
Keywords:kbhowto kbXML KB314180 kbAudDeveloper