Microsoft KB Archive/310286

= How to list folders and items in a mailbox on an Exchange 2000 Server computer by using WebDAV in Visual C# =

Article ID: 310286

Article Last Modified on 12/11/2006

-

APPLIES TO


 * Microsoft Visual C# 2005
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q310286



SUMMARY
This article describes how to use Microsoft XML 3.0 or Microsoft XML 4.0 to list folders and items in a user's mailbox on Exchange 2000 Server computer by using Microsoft Visual C#.



MORE INFORMATION
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. Under Project Types, select Visual C# Projects

Note In Visual Studio 2005, click Visual C# under Project Types. Under Templates, select Console Application, and then click OK. In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. Add a reference to the XML 3.0 component or to the XML 4.0 component. To do this, follow these steps:  On the Project menu, click Add Reference. On the COM tab, click Microsoft XML, v3.0 or Microsoft XML, v4.0, and then click Select.

Note In Visual Studio 2005, you do not have to click Select.</li> In the Add References dialog box, click OK to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the code window, replace all the code with: using System; using System.Reflection;

namespace WebDav {   class Class1 {          public static void Main(String [] args) {           try {                          MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30;

//TODO: To list items, uncomment &quot;const bool bListItems = false;&quot; const bool bListFolders = true; //const bool bListItems = false; String sUrl; //TODO: Replace ExchServer with your Exchange server and UserAlias with your user alias. sUrl= &quot;http://ExchServer/Exchange/UserAlias/Inbox&quot;;

oXMLHttp.open(&quot;SEARCH&quot;, sUrl, false, &quot;UserDomain\UserAlias&quot;, &quot;UserPassword&quot;); //TODO: Use this query to list items. /*String sQuery; sQuery = &quot;<?xml version='1.0'?>&quot; + &quot;<g:searchrequest xmlns:g='DAV:'>&quot; + &quot;<g:sql>SELECT \&quot;DAV:displayname\&quot; &quot; + &quot;FROM SCOPE('SHALLOW TRAVERSAL OF \&quot;&quot; + sUrl + &quot;\&quot;')&quot; + &quot; WHERE \&quot;DAV:isfolder\&quot; = &quot; + bListItems.ToString+

&quot;</g:sql>&quot; + &quot;</g:searchrequest>&quot;; */

//TODO: Use this query to list folders. String sQuery; sQuery = &quot;<?xml version='1.0'?>&quot; + &quot;<g:searchrequest xmlns:g='DAV:'>&quot; + &quot;<g:sql>SELECT \&quot;DAV:displayname\&quot; &quot; + &quot;FROM SCOPE('SHALLOW TRAVERSAL OF \&quot;&quot; + sUrl + &quot;\&quot;')&quot; + &quot; WHERE \&quot;DAV:isfolder\&quot; = &quot; + bListFolders.ToString + &quot;</g:sql>&quot; + &quot;</g:searchrequest>&quot;;

oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;); oXMLHttp.setRequestHeader(&quot;Translate&quot;, &quot;f&quot;); oXMLHttp.setRequestHeader(&quot;Content-Length&quot;, &quot;&quot; + sQuery.Length); Console.WriteLine(sQuery); oXMLHttp.send(sQuery);

Console.WriteLine(oXMLHttp.status); Console.WriteLine(oXMLHttp.statusText); Console.WriteLine(oXMLHttp.responseText); }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }

}   } } </li> Modify the code where you see the &quot;TODO&quot; comments.</li> Press F5 to build and to run the program.</li> Verify the subfolders in the URL specified are received from the response.</li></ol>

Additional query words: Microsoft XML, list folders,items,mailbox,Exchange server

Keywords: kbhowto kbmsg kbxml kbcode KB310286

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.