Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 314180 - Last Review: July 21, 2004 - Revision: 1.4
How to retrieve all the items in a public folder on a computer that is running Exchange 2000
This article was previously published under Q314180
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.
To retrieve all the items from a public folder on a computer that is running Exchange 2000, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- In the Visual Basic Projects types list, click Console Application.
By default, the Module1.vb file is created. - Add a reference to Microsoft XML 3.0. To do so, follow these steps:
- On the Project menu, click Add Reference.
- Click the COM tab, locate Microsoft XML v3.0, and then click Select.
- In the Add References dialog box, click OK.
- If you are prompted to
generate wrappers for the libraries that you selected, click Yes.
- 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
- Search for TODO in the code, and then modify the code for your environment.
- Press F5 to build and to run the program.
- Make sure that the DisplayName property of the items in the folder was received.
For information about the WebDAV protocol, visit the following MSDN Web site:
APPLIES TO
- Microsoft Exchange 2000 Server Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft XML Parser 3.0
- Microsoft XML Core Services 4.0
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate