BeginsWith Element (Query)

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 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>

Attributes

Attribute

Description

None

N/A

Child Elements

FieldRef, Value, XML

Parent Elements

And, Or, Where

Occurrences

Minimum: 0

Maximum: Unbounded

Example

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>";
}

See Also

Reference

Contains Element (Query)