I'm trying to add new items into a Sharepoint List, using a winforms C# app, but I'm getting an error as if the app didn't find the list fields.
My code:
using SPC = Microsoft.SharePoint.Client;
(...)
string siteUrl = "https://sharepoint.company.com/sites/ProjectX";
SPC.ClientContext clientContext = new SPC.ClientContext(siteUrl);
string userName = "someone.surname";
SecureString password = new SecureString();
foreach (char c in "MyPaSsWoRd".ToCharArray()) password.AppendChar(c);
clientContext.Credentials = new NetworkCredential(userName, password, "MyDomain");
SPC.Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
SPC.List oList = web.Lists.GetByTitle("List Y");
clientContext.Load(oList);
clientContext.ExecuteQuery();
SPC.ListItemCreationInformation listCreationInformation = new SPC.ListItemCreationInformation();
SPC.ListItem oListItem = oList.AddItem(listCreationInformation);
oListItem["field 1"] = "a";
oListItem["field 2"] = "b";
oListItem["user"] = "someone.surname";
oListItem["date 1"] = "01/01/2015";
oListItem["field 3"] = "99";
oListItem.Update();
clientContext.ExecuteQuery();
Error ocurring in the last code line:
Column 'field 1' does not exist. It may have been deleted by another user. /sites/ProjectX/Lists/List_Y
Any tip?
PS.: Yes, there is a field named "field 1" on the "List Y".
Thanks!