mercredi 11 mars 2015

Issues when trying to add new list items using the reference Microsoft.Sharepoint.Client

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 = "http://ift.tt/1EAbjoM";

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!


Aucun commentaire:

Enregistrer un commentaire