Creating Search Folders

Creating Search Folders

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.To create a search folder using the World Wide Web Distributed Authoring and Versioning (WebDAV) protocol

  1. Create a MKCOL Method WebDAV request. The request Uniform Resource Identifier (URI) should be the location of the new search folder, for example, http://myserver/pub2/folders/search_folder.
  2. In the body of the request, send a DAV:propertyupdate XML stream. Specify the Structured Query Language (SQL) statement in the DAV:sql portion of the DAV:searchrequest property.
  3. Send the request to the HTTP service on the machine that hosts the Exchange store in which the new search folder is to be created.
  4. If successful, the HTTP service will respond with the status code 207 (Multi-Status), the new folder creation will have the status 201 (Created), and the property update will have the status 200 (OK).

Note  Search folders cannot be created in the one public folder tree (and associated public store) designated for MAPI clients. If you attempt to create a search folder in this public folder tree, the Web server will return an error. This public folder tree is, by default, made available through the '/public' HTTP virtual root.

The following example shows what the request body might look like.

MKCOL /pub2/search_folder/ HTTP/1.1
Content-Length: XXX
Content-type: text/xml

<?xml version="1.0"?>
<a:propertyupdate xmlns:a="DAV:" >
                     Select "DAV:displayname"
                     FROM Scope('shallow traversal of "/pub2/folder1 "')
                     WHERE ""DAV:ishidden"" = false AND
                           ""DAV:isfolder"" = false

In addition, a successful response might be:

HTTP/1.1 207 Multi-Status
Server: Microsoft-IIS/5.0
Date: Tue, 22 Feb 1999 12:54:46 GMT
WWW-Authenticate: Negotiate AADAB...
MS-Exchange-Permanent-URL: http://hostname/pub2/-FlatUrlSpace-/ab7e2af09631
Location: http://hostname/pub2/search_folder/
Timeout: Infinity
Repl-UID: <rid:ab7e2af09631b745981c6d39445456f2000000001371>
Content-Type: text/xml
Content-Length: XXX
ResourceTag: <rt:ab7e2af09631b745981c6d39445456f2000000001371ab7e2af09631b745981

<?xml version="1.0"?>
<a:multistatus xmlns:a="DAV:">
    <a:status>HTTP/1.1 201 Created</a:status>
       <a:status>HTTP/1.1 200 OK</a:status>

Note  To reiterate, you can create search folders in every mailbox store and every public folder tree except the public folder tree designated for MAPI clients. This public folder tree is, by default, made available through the '/public' virtual root.

The following example uses an instance of the Microsoft.XMLHTTP Component Object Model (COM) class to create and send the request to the server. It then returns a reference to the object. The XML stream for the request body is hard-coded by using a string variable. You can also use an instance of the Microsoft.XMLDOM COM class to create the XML stream for the request body.


// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
function createSearchFolder( folderURL, SQL ) {

  // Initialize the XMLHTTP request object.
  var Req;
  Req = new ActiveXObject("Microsoft.XMLHTTP");

  // Open the request object with the MKCOL method and
  // specify that it will be sent asynchronously.
  Req.Open("MKCOL", folderURL, false);

  // Build the XML request body.
  strR = "<?xml version='1.0'?>";
  strR += "<d:propertyupdate xmlns:d='DAV:'>";
  strR += "<d:set><d:prop><d:searchrequest><d:sql>" + SQL + "</d:sql>";
  strR += "</d:searchrequest></d:prop></d:set></d:propertyupdate>";

  // Set the Content-Type header to "text/xml".
  Req.SetRequestHeader("Content-type:", "text/xml");

  // Send the MKCOL method request with the XML body.

  // An error occurred on the server.
 if(Req.status >= 500)
   this.document.writeln("Status: " + Req.status);
   this.document.writeln("Status text: An error occurred on the server.");

   this.document.writeln("Status: " + Req.status);
   this.document.writeln("Status text: " + Req.statustext);

  return Req;

This section also contains the following topics.

Exchange Store Search Folders

Search Folder Properties

Search Folder Items

WebDAV Search Folder Creation Protocol Command

Example Search Folder HTTP Request and Response

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.