Wednesday, 15 January 2014

Update a LookupMulti Column value in SharePoint using Client Object Model C#

Update the value of LookupMulti column in SharePoint using the Client Object Model

ClientContext ctx = new
ctx.Credentials =
new SharePointOnlineCredentials(userName, passWord);

List list = ctx.Web.Lists.GetByTitle("ListTitle");
ListItem currentItem = list.GetItemById(1);

FieldLookupValue[] lookupFieldValCollection =
new FieldLookupValue[3];FieldLookupValue lookupFieldA = new FieldLookupValue();
lookupFieldA.LookupId = 2;
lookupFieldValCollection.SetValue(lookupFieldA, 0);

FieldLookupValue lookupFieldB = new FieldLookupValue();
lookupFieldB.LookupId = 4;
lookupFieldValCollection.SetValue(lookupFieldB, 1);

FieldLookupValue lookupFieldC = new FieldLookupValue();
lookupFieldC.LookupId = 6;
lookupFieldValCollection.SetValue(lookupFieldC, 2);

currentItem["MultiLookupValCol"] = lookupFieldValCollection;


Two important thing I would like to share here,
  • Initially I tried to pass an array of an array of integer [containing the ids of the item] to the LookupMulti column which generated the error: Value does not fall between the specified range
  • Another thing was then I created a List of type FieldLookupValue and then I passed the List to the column using its ToArray(). I guess we just had to pass the array of FieldLookupValue. However, this resulted in the error: Unknown Error. Don't know what that means.

Finally, I can say that create the array of type FieldLookupValue and populate this array using its SetValue method only.

From now on, I'll be posting all the sharepont relates blogs on the following url. The current post will continue to exist here however, no updates will be made to them and no new post regarding SharePoint will be added to this channel.

1 comment:

  1. Very helpful article ! I was always curious about all these complex algorithms that are being used in these ssl encryptions.