Programming DASL Search

WebDAV .NET Client Library provides methods for detecting DASL search support, submitting search queries, and requesting custom properties to be returned in search results. You can specify which properties to search and if file content should be searched.

Submitting Search Query

To submit a search request the library provides IFolder.SearchByQueryAsync() function. Here is the example of search request:

 // Build search query
 SearchQuery oSearchQuery = new SearchQuery("Sales Report%");

 // By default WebDAV Ajax Client search by DisplayName property.
 // You can add other properties to this list.
 oSearchQuery.LikeProperties.Add(new PropertyName("creator-displayname", "DAV:"));
 oSearchQuery.LikeProperties.Add(new PropertyName("comment", "DAV:"));

 // Disable search by file content
 oSearchQuery.EnableContains = false;

 string license = "<?xml version=\"1.0\" ...";
 WebDavSession session = new WebDavSession(license);
 Uri uri = new Uri("https://serv/folder/");
 IFolder folder = await session.GetFolderAsync(uri);

 IHierarchyItem[] items = await folder.SearchByQueryAsync(oSearchQuery);

 foreach (IHierarchyItem item in items)
 {
      Console.WriteLine(item.DisplayName);
 }

By default, the search will be performed using the display name and content. You can use SearchQuery.LikeProperties list to add more properties to the search list.

Requesting Custom Properties

In many cases, you will need additional data being returned with each hierarchy item in search results. For example, you may need a piece of text around the search phrase or name of the author that updated the document last time. You can request additional properties by specifying them in a search request in SearchQuery.SelectProperties list. The requested properties will be returned in IHierarchyItem.Properties:

            // Build search query
            SearchQuery oSearchQuery = new SearchQuery("Note%");

            // Ask server to return MyNS:snippet property with each item.
            PropertyName snippetPropName = new PropertyName("snippet", "MyNS:");
            oSearchQuery.SelectProperties.Add(snippetPropName);

            string license = "<?xml version=\"1.0\" ...";
            WebDavSession session = new WebDavSession(license);
            Uri uri = new Uri("https://serv/folder/");
            IFolder folder = await session.GetFolderAsync(uri);

            IHierarchyItem[] items = await folder.SearchByQueryAsync(oSearchQuery);

            foreach (IHierarchyItem item in items)
            {
                Console.WriteLine(item.DisplayName + " " + Array.Find(item.Properties, element => element.Name == snippetPropName));
            }

Search Phrase Wildcards and Escaping

To add wildcards to your search phrase use DASL wildcard characters:

  • ‘%’ – to indicate one or more characters.
  • ‘_’ – to indicate exactly one character.
new ITHit.WebDAV.Client.SearchQuery('Sales Report 201_');

Note that the WebDAV Ajax Library will pass the search phrase to the server without modification. As though if ‘%’, ‘_’ or ‘\’ characters are used in a search phrase, they must be escaped as ‘\%’, ‘\_’ and ‘\\’.