ClientContext ctx = new ClientContext("http://sp2010Server/sites/mySite");
Web web = ctx.Web;
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem listItem = web.Lists.GetByTitle("Site Requests").AddItem(itemCreateInfo);
listItem["Title"] = "title";
listItem["Description"] = "description";
listItem["Url"] = "someUrl";
listItem.Update();
我有上面的代码来更新sp2010列表,但它从不在列表中添加项目。我手动创建了一个名为“站点请求”的列表,并希望将一个项目添加到此列表中。我这样做对吗?我没有收到任何错误,代码执行正常,但列表中没有新项目。
答案 0 :(得分:2)
请参阅:
http://msdn.microsoft.com/en-us/library/ee539976.aspx
ClientContext clientContext = new ClientContext("http://sp2010Server/sites/mySite");
SP.List oList = clientContext.Web.Lists.GetByTitle("Site Requests");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "title";
oListItem["Description"] = "description";
oListItem["Url"] = "someUrl";
oListItem.Update();
clientContext.ExecuteQuery();