#henrik

development and technology stuff

SPListItem - SPFieldLookupValue

If I use the SharePoint object-model to set items my "normal" approach is:

SPListItem item;
item["fieldName"] = "value";

This works as expected until the field in question is a lookup-field. Using the approach mentioned above I always got an exception. The reason for this is, that a lookup values always contain a key and value ==> 1#;Value So the correct code would look like this:

int lookupId;
string lookupValue;
item["fieldName"] = new SPFieldLookupValue(lookupId, lookupValue);

Thanks to Sridhar's Blog.

Filed under  //   Development   SharePoint   Sharepoint Development   c#   object-model  
Posted May 21, 2009