views:

701

answers:

1

My SharePoint list has a column that allows multiple lookup values. My C# control (within a webpart) allows the user to make multiple selections from a list box. I split these values into an array - each array member being a selected value that needs to be updated in the same SPListItem column.

I know that the selections are being passed in properly from the list box - I just need to add this group of values to the same column in the SPListItem.

Where am I going wrong?

SPFieldLookupValueCollection MyCollection = new SPFieldLookupValueCollection();
for (int i = 0; i < MyArrayOfSelections.Length; i++)
{
   if (MyLookupList["LookupColumn"].ToString() == MyArrayOfSelections[i].ToString())
   {
      MyID = int.Parse(MyLookupList[i]["ID"].ToString());
      SPFieldLookupValue thisSelection = new SPFieldLookupValue(MyID,MyArrayOfSelections[i].ToString());
      MySubCollection.Add(thisSelection);
      }
   }
   ListIWantToUpdate["ColumnWithMultipleLookupSelections"] = SubCollection;
   ListIWantToUpdate.Update();
   site.Update();
A: 

The last rows of the code example are confusing (maybe it's just variable naming). If you are just updating the data, you never need to update neither the SPList object (this requires "Manage lists" permission on the particular list, nor SPSite ojbect (requires you to be site administrator or owner). So, this code will not run succcessfuly for a regular user.

naivists
I don't know how I missed the email notification when you answered! Just ran across this today; I appreciate your response very much. Re: the confusing naming condition, mea culpa. I am updating a listItem. Thank you for the correction on the SPSite object. Your post was helpful.
elizabeth