有人能告訴我我在做什麼錯嗎?我試圖列表名稱傳遞給將刪除列表中的所有行的方法:按價值傳遞 - 列表名稱
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()方法?
非常感謝您的回覆。你會友善地告訴我該怎麼做嗎? – SharePointDummy
我用代碼示例更新了我的答案。 –
Thansks!這工作完美 – SharePointDummy