有人可以告诉我我在这里做错了什么吗?我试图将列表名称传递给将删除列表中所有行的方法:
public static void DeleteLastUpdate(Microsoft.SharePoint.Client.List oList)
{
using (var context = new ClientContext(FrontEndAppUrl))
{
var ss = new System.Security.SecureString();
Array.ForEach("hhh".ToCharArray(), (c) => { ss.AppendChar(c); });
context.Credentials = new SharePointOnlineCredentials("yyy", ss);
var web = context.Web;
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy></Query></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
context.Load(collListItem);
context.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
string i = oListItem["ID"].ToString(); ;
ListItem ListItemToDelete = oList.GetItemById(i);
ListItemToDelete.DeleteObject();
context.ExecuteQuery();
}
oList.Update();
}
}
public static void GetCountry()
{
using (var context = new ClientContext(FrontEndAppUrl))
{
Microsoft.SharePoint.Client.List oList_Country = context.Web.Lists.GetByTitle("LISTNAME");
DeleteLastUpdate(oList_Country);
}
}
我得到的错误是在 context.Load(collListItem);
它说该对象在与与该对象关联的上下文不同的上下文中使用。我还能如何将列表的值传递给 Delete() 方法?