SharePoint Short #6
To retrieve all SPListItem objects that have a specified field value, instead of writing a CAML query, use the following LINQ statement:
public List<SPListItem> GetItemsContainingValue(SPList list, Guid fieldId, string match) { List<SPListItem> matchingItems = (from SPListItem listItem in list.Items where listItem.Fields.Contains(fieldId) && listItem[fieldId] != null && listItem[fieldId].ToString().Equals(match, StringComparison.InvariantCultureIgnoreCase) select listItem).ToList<SPListItem>(); return matchingItems; } |
Thanks!
It’s helpfull, thanks.