Microsoft KB Archive/310275

= How to create a search folder by using WebDAV in Visual C# =

Article ID: 310275

Article Last Modified on 6/29/2007

-

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 Q310275



SUMMARY
This article describes how to use Microsoft XML 3.0 or Microsoft XML 4.0 to create a search folder by using Web Distributed Authoring and Versioning (WebDAV) in Microsoft Visual C#.



MORE INFORMATION
To create a search folder in Visual C#, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. In the Visual C# Projects types list, click Console Application.

By default, Class1.cs is created.

Note In Microsoft Visual C# 2005, click Visual C# under Console Application. By default, Program.cs is created. Add a reference to Microsoft XML v3.0 or to Microsoft XML v4.0. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, locate Microsoft XML v3.0 or Microsoft XML v4.0 and then click Select.

Note In Microsoft Visual C# 2005, you do not have to click Select. In the Add References dialog box, click OK.</li> If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the code window, replace the code with the following: using System;

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

// TODO: Replace with your new search/source folder URLs String sUrl = &quot;http://ExchServer/MyTLH/MyApplication/SearchFolder&quot;; String sSourceUrl = &quot;http://ExchServer/MyTLH/MyApplication/SourceFolder&quot;;

String sQuery = &quot;<?xml version='1.0'?>&quot; + &quot;<a:propertyupdate xmlns:a='DAV:' xmlns:m='urn:schemas:mailheader:'>&quot; + &quot;<a:set>&quot; + &quot;<a:prop>&quot; + &quot;<a:searchrequest>&quot; + &quot;<a:sql>&quot; + &quot;Select \&quot;DAV:displayname\&quot;, \&quot;urn:schemas:mailheader:subject\&quot;&quot; + &quot; FROM SCOPE('SHALLOW TRAVERSAL OF \&quot;&quot; + sSourceUrl + &quot;\&quot;')&quot; + &quot; Where \&quot;urn:schemas:mailheader:subject\&quot; = 'Test1'&quot; + &quot;</a:sql>&quot; + &quot;</a:searchrequest>&quot; + &quot;</a:prop>&quot; + &quot;</a:set>&quot; + &quot;</a:propertyupdate>&quot;;

oXMLHttp.open(&quot;MKCOL&quot;, sUrl, false, &quot;UserDomain\UserAlias&quot;, &quot;UserPassword&quot;);

oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;); oXMLHttp.setRequestHeader(&quot;Translate&quot;, &quot;f&quot;); //Console.WriteLine(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> Search for TODO in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Make sure that the search folder that you just created works.</li></ol>

<div class="references_section">