Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Contains Element (Query)

Windows SharePoint Services 3

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Searches for a string anywhere within a column that holds Text or Note field type values.


<Contains>
  <FieldRef Name = "Field_Name"/>
  <Value Type = "Field_Type"/>
  <XML />
</Contains>

Attribute

Description

None

N/A

Minimum: 0

Maximum: Unbounded

The following example uses the Contains element within a string that is assigned to the Query property to return the titles of items where the Conference column value begins with "Morning" and contains "discussion session".

SPWeb mySite = SPControl.GetContextWeb(Context);

SPList list = mySite.Lists["List_Name"];

SPQuery query = new SPQuery();
query.Query = "<Where><And><BeginsWith><FieldRef Name="Conference"/>" + 
   "<Value Type="Note">Morning</Value></BeginsWith>" + 
      "<Contains><FieldRef Name="Conference" />
   <Value Type="Note">discussion session</Value>" + 
      "</Contains></And></Where>";

SPListItemCollection myItems = list.GetItems(query);

foreach (SPListItem item in myItems)
{
   Label1.Text += item["Title"] + "<BR>";
}
Show:
© 2015 Microsoft