Datasheet
Chapter 1: Workfl ow Programming Principles
31
set { base.SetValue(SiteUrlProperty, value); }
}
public override bool Evaluate(Activity activity,
IServiceProvider provider)
{
bool success = false;
using (SPSite siteCollection = new SPSite(this.SiteUrl))
{
using( SPWeb web = siteCollection.OpenWeb())
{
SPList list = web.Lists[ListName];
SPListItem item = list.GetItemById(ItemId);
string str = item[FieldName].ToString();
success = ((str != null) & & str.Contains(Keywords));
}
}
return success;
}
}
}
This custom condition basically determines whether a specified field of a specified list item of a specified
SharePoint list in the top - level site of a specified site collection contains the specified keywords. As such,
the condition exposes five properties that must be set for this condition to operate properly. As shown
in the example, your condition can expose as many properties as necessary. Next, let ’ s look at the
implementation of the Evaluate method. This method first instantiates an SPSite object so it can
programmatically access the site collection with the specified URL:
SPSite siteCollection = new SPSite(this.SiteUrl);
Next, it accesses the SPWeb object that represents the top - level site in this site collection:
SPWeb web = siteCollection.OpenWeb();
It then uses the list name as an index into the Lists collection property of this SPWeb object to return a
reference to the SPList object that represents the list:
SPList list = web.Lists[ListName];
Next, it invokes the GetItemById method on this SPList object, passing in the ID of the list item, to return
a reference to the SPListItem object that represents the list item:
SPListItem item = list.GetItemById(ItemId);
Then, it uses the field name as an index into this SPListItem object to return the value of the field:
string str = item[FieldName].ToString();
Finally, it returns a Boolean value that specifies whether this field value contains the specified keywords:
return ((str != null) & & str.Contains(Keywords));
c01.indd 31c01.indd 31 8/25/08 4:03:00 PM8/25/08 4:03:00 PM