Tech Space

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

//


// Returns the Single Value of a Lookup Field.
//


private static string GetFieldValueLookup(this SPListItem item, string fieldName)
{
if (item != null)
{
SPFieldLookupValue lookupValue = new SPFieldLookupValue(item[fieldName] as string);
return lookupValue.LookupValue;
}
else
{
return string.Empty;
}
}


Example:
// Reads the value of a SPFieldLookup field
string value = item.GetFieldValueLookup("LookupFieldName");

0 comments:

Post a Comment