다음을 통해 공유


Creating Search Folders

Topic Last Modified: 2006-06-12

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
Host: somedomain.example.com
Content-Length: XXX
Content-type: text/xml

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

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
b745981c6d39445456f2-17/
Location: http://hostname/pub2/search_folder/
Timeout: Infinity
Repl-UID: <rid:ab7e2af09631b745981c6d39445456f2000000001371>
Content-Type: text/xml
Content-Length: XXX
ResourceTag: <rt:ab7e2af09631b745981c6d39445456f2000000001371ab7e2af09631b745981
c6d39445456f2000000001573>

<?xml version="1.0"?>
<a:multistatus xmlns:a="DAV:">
  <a:response>
    <a:href>http://hostname/pub2/search_folder</a:href>
    <a:status>HTTP/1.1 201 Created</a:status>
    <a:propstat>
       <a:status>HTTP/1.1 200 OK</a:status>
       <a:prop><a:searchrequest/></a:prop>
    </a:propstat>
  </a:response>
</a:multistatus>

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.

JScript

Example

// 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.
  Req.send(strR);

  // 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.");
 }

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

  return Req;
}