I am trying to submit some data from a winform into a SharePoint list. Most of the items can submit fine except for the a field which is a user lookup field. I have done this in the past with a powershell script from the server side, but I am unable to get it done from the client side.
I get the idea that I am to retrieve the userid but the examples out there are a bit confusing maybe somebody can help me with this piece of code:
ClientContext context = new ClientContext(SharePointAddress);
List PANlist = context.Web.Lists.GetByTitle(SharePointList);
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = PANlist.AddItem(itemCreateInfo);
newItem[@"First_x0020_Name"] = dr.Cells["First Name"].Value.ToString();
newItem[@"Middle_x0020_Name"] = dr.Cells["Middle Name"].Value.ToString();
newItem[@"Last_x0020_Name"] = dr.Cells["Last Name"].Value.ToString();
newItem.Update();
context.ExecuteQuery();
If I try (where Existing User is a lookup people only field and string is "John Doe"):
newItem[@"Existing_x0020_User"] = dr.Cells["Existing User"].Value.ToString();
it fails with the error:
"Invalid data has been used to update the list item. The field you are trying to update may be read only"
Can you provide an example or help on how do I submit "John Doe" on the lookup field?
Thanks