如何刷新ListItem或从URL重新加载它

时间:2019-02-12 17:59:54

标签: c# sharepoint csom

问题:在下面的ListItem中,我分为两部分。

第1部分打开一个excel文件并对其进行修改 第2部分更新了Microsoft.SharePoint.Client.ServerException: 'Version conflict.'字段中的3个

两个部分都可以单独工作,但是同时启用了这两个部分,第2部分无法做到ListItem.RefreshLoad();可以理解

问题:如何在第1部分和第2部分之间刷新/重新加载ListItem?

我尝试了ListItem.GetFromURL(); 而且我四处寻找与 ClientContext cc = new ClientContext(site) SecureString pass = new SecureString(); Web web = cc.Web; foreach (char c in "password".ToCharArray()) { pass.AppendChar(c); } cc.Credentials = new SharePointOnlineCredentials("User@Domain.com", pass); Microsoft.SharePoint.Client.List list = web.Lists.GetByTitle("MyLibrary"); CamlQuery qry = new CamlQuery { ViewXml = "<View><Query><Where><Contains><FieldRef Name='Active'/><Value Type='Boolean'>1</Value></Contains></Where></Query></View>" }; Microsoft.SharePoint.Client.ListItemCollection listItems = list.GetItems(qry); cc.Load(listItems); cc.ExecuteQuery(); foreach (Microsoft.SharePoint.Client.ListItem listItem in listItems) { //PART 1 //Open the file //Modify the File //Save the file //PART 2 listItem["Updated"] = DateTime.Now; listItem["Update_x0020_Duration"] = totalTime; listItem["System_x0020_Comment"] = "TestComment"; listItem.Update(); cc.ExecuteQuery(); } 类似的东西,但似乎找不到我想要的东西

<option value="1">Pizza1</option>
<option value="2">Pizza2</option>

1 个答案:

答案 0 :(得分:1)

根据我的经验Microsoft.SharePoint.Client命名空间可能有点棘手。
过去,我一直在为同一个问题而苦苦挣扎。
这是基于您的代码的一般想法。请阅读评论:

    ClientContext cc = new ClientContext(site);
    // try to use the List object, using the name of the list as the parameter
    List oList = cc.Web.Lists.GetByTitle(listName);
    // pass the credantials!
    cc.Credentials = new System.Net.NetworkCredential(< username >, < password >, < domain >);
    // another option - default NetworkCredentials credantials
    // context.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

    // pass the uniq id of the record
    ListItem listItem = oList.GetItemById(id);
    // now you can to this
    // ...............
    listItem["System_x0020_Comment"] = "TestComment";
    listItem.Update();
    cc.ExecuteQuery();