Tech Space

The Technical Solution Space for SharePoint 2010, MOSS 2007, and .Net (C#, VB.Net)

//


// Returns the value of a Lookup-Field with multiple values.
//


public static IEnumerable GetFieldValueLookupCollection(this SPListItem item, string fieldName)
{
List result = new List();
if (item != null)
{
SPFieldLookupValueCollection values = item[fieldName] as SPFieldLookupValueCollection;

foreach (SPFieldLookupValue value in values)
{
result.Add(value.LookupValue);
}
}
return result;
}


Example:
// Read lookup values of a SPFieldLookup field with multiple values allowed

IEnumerable values = item.GetFieldValueLookupCollection("MultiLookupFieldName");

0 comments:

Post a Comment