Searching for recently opened work boxes

The following code example creates a simple query using the WBQuery class in order to search for WBs within a WBC that have recently been opened. It does this by finding the work boxes that are in the 'Open' state and then ordering them by the date that they were opened. In the example, the foreach loop is limited to use only the first 20 items found.
using (WBCollection collection = new WBCollection("http://collection/myWBC"))
{
    WBQuery query = new WBQuery();
    query.AddEqualsFilter(WBColumn.WorkBoxStatus, "Open");
    query.OrderByDescending(WBColumn.WorkBoxDateLastOpened);

    int count = 0;
    foreach (WorkBox workBox in collection.GetWorkBoxes(query))
    {
        // ... do something with the work box object

        workBox.Dispose();

        count++;
        if (count >= 20) break;
    }
}

An important performance point to note here is that the method 'GetWorkBoxes' is wrapping SPListItem objects with the WorkBox object. It is not creating expensive SPWeb objects. The relevant SPWeb object will only be created if you actually use one of the properties on a workBox object that needs the underlying SPWeb object (such as calling workBox.Web )

Last edited May 7, 2014 at 10:48 PM by OliSharpe, version 2

Comments

No comments yet.