我想更新共享点中的“创建者”列。为此,我只需要使用CSOM,因为我没有共享点服务器dll。我在此编写代码...
ClientContext cc = new ClientContext ("http://sharepoint...");
List list = cc.web.Lists.GetByTitle("sharepointlistname");
cc.Load(list);
ListItem item = list.GetItemById(13);//In this case, i want to update only id=13. I want to know code for all records also.
cc.Load(item);
cc.ExecuteQuery();
item("Created by") = "Dinesh";
item.Update();
当我运行上述代码时,出现此错误...
共享点列表无效的数据已用于更新列表项。您尝试更新的字段可能是只读的
答案 0 :(得分:1)
“创建者”字段的内部名称为“作者”,它是“人员”字段,请像这样更新:
ClientContext ctx = new ClientContext("http://sp/sites/dev");
List list = ctx.Web.Lists.GetByTitle("MyList");
Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
//CamlQuery to filter items which created in Today
camlQuery.ViewXml =
@"<View>
<Query>
<Where><Eq><FieldRef Name='Created' /><Value Type='DateTime'><Today /></Value></Eq></Where>
</Query>
</View>";
ListItemCollection items = list.GetItems(camlQuery);
ctx.Load(items);
ctx.ExecuteQuery();
User theUser = ctx.Web.EnsureUser("Contoso\\Jerry");
ctx.Load(theUser);
ctx.ExecuteQuery();
foreach (var item in items)
{
item["Editor"] = theUser;
item["Author"] = theUser;
item.Update();
}
ctx.ExecuteQuery();