BeginsWith Element (Query)

Last modified: July 15, 2011

Applies to: SharePoint Foundation 2013 | SharePoint Server 2013

In this article
Attributes
Child Elements
Parent Elements
Occurrences

Searches for a string at the start of a column that holds Text or Note field type values.


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

Attribute

Description

None

N/A

Minimum: 0

Maximum: Unbounded

The following example uses the BeginsWith element within a string that is assigned to the Query property to return the titles of items within a list where a Journal column begins with "City".

SPWeb mySite = SPControl.GetContextWeb(Context);

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

SPQuery query = new SPQuery();
query.Query = "<Where><BeginsWith><FieldRef Name="Journal"/>" + 
   "<Value Type="Note">City</Value></BeginsWith></Where>";

SPListItemCollection myItems = list.GetItems(query);

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