I am trying to update a multi value lookup column in SP 2013 On Premise. I have gone through various forums for achieving this and as suggested, I am getting values in SPFieldLookupValueCollection. Sample values in this are of the format:
4;#N/A
The problem I am facing is if I try to update the column using :
item["ColumnName"] = SPfieldLookupvaluecollection object
I am getting an exception saying that item is being updated in the wrong format. the closest I've come to updating the lookup column is by using a foreach loop and iterating the lookupvaluecollection. But this doesn't help me since I have multiple values in the SPfieldLookupvaluecollection object and only the last value is getting updated. Any help would be appreciated.
Thanks
Edit : Updating with the code snippet.
Microsoft.SharePoint.Client.File newfile = myclientcontext.Web.GetFileByServerRelativeUrl("Relative path to file here"); myclientcontext.load(newfile); ListItem item = newfile.ListItemAllFields;
//I'm reading lookup values from a csv file and updating accordingly
if (rowfilter.ItemArray[0].ToString() != "") { string[] values = rowfilter.ItemArray[0].ToString().Split(';');
SPFieldLookupValueCollection fieldlookup = GetLookupFieldIDs(values, "LookupListName"); }
//Above method returns values in the format 4;#N/A 106;#Building //This is what i've tried
- item["ColumnName"] = fieldlookup;
- var arraylist = new ArrayList(); foreach (SPFieldLookupValue value in fieldlookup) { arraylist.Add(value.LookupId); } item["ColumnName"] = arraylist.ToArray();
However I get an error always. Any help would be appreciated.