C# caml查询在sharepoint online中无法正常工作

C# caml查询在sharepoint online中无法正常工作,c#,sharepoint,sharepoint-online,caml,C#,Sharepoint,Sharepoint Online,Caml,我需要得到列表项目,这是说7天以上,并删除他们。我尝试使用caml查询,它在sharepoint 2010中运行良好,但当我尝试在sharepoint Online中使用caml查询时,它会获取所有列表项并将其删除,而不管条件如何 public static bool removeOldEntries(string listName, int offset) { bool successFlag = true; try {

我需要得到列表项目,这是说7天以上,并删除他们。我尝试使用caml查询,它在sharepoint 2010中运行良好,但当我尝试在sharepoint Online中使用caml查询时,它会获取所有列表项并将其删除,而不管条件如何

    public static bool removeOldEntries(string listName, int offset)
    {
        bool successFlag = true;
        try
        {
            using (var context = new ClientContext(siteURL))
            {
                SecureString password = ToSecureString(pwd);
                context.Credentials = new SharePointOnlineCredentials(userName, password);
                Web web = context.Web;
                var list = context.Web.Lists.GetByTitle(listName);
                if (list != null)
                {
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<Where><Leq><FieldRef Name='Modified'/><Value Type='DateTime'><Today OffsetDays='-" + offset + "'/></Value></Leq></Where>";
                    ListItemCollection collListItem = list.GetItems(camlQuery);
                    context.Load(collListItem, items => items.Include(
                                         item => item["ID"]));
                    context.ExecuteQuery();
                    if (collListItem.Count > 0)
                    {
                        foreach (ListItem oListItem in collListItem)
                        {
                            ListItem itemToDelete = list.GetItemById(int.Parse(oListItem["ID"].ToString()));
                            itemToDelete.DeleteObject();
                            context.ExecuteQuery();
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            successFlag = false;
        }
        return successFlag;
    }
公共静态bool removeOldEntries(字符串列表名,int偏移量)
{
bool successFlag=true;
尝试
{
使用(var context=newclientcontext(siteURL))
{
SecureString password=tosecuretring(pwd);
context.Credentials=新的SharePointOnlineCredentials(用户名、密码);
Web=context.Web;
var list=context.Web.Lists.GetByTitle(listName);
如果(列表!=null)
{
CamlQuery CamlQuery=新的CamlQuery();
camlQuery.ViewXml=“”;
ListItemCollection collListItem=list.GetItems(camlQuery);
Load(collListItem,items=>items.Include(
item=>item[“ID”]);
context.ExecuteQuery();
如果(collListItem.Count>0)
{
foreach(collListItem中的ListItem oListItem)
{
ListItemToDelete=list.GetItemById(int.Parse(oListItem[“ID”].ToString());
itemToDelete.DeleteObject();
context.ExecuteQuery();
}
}
}
}
}
捕获(例外情况除外)
{
successFlag=false;
}
返回成功标志;
}

提前感谢您的帮助。

首先尝试在视图xml中添加标记

所以看起来应该是这样的

 camlQuery.ViewXml = "<Query><Where><Leq><FieldRef Name='Modified'/><Value Type='DateTime'><Today OffsetDays='-" + offset + "'/></Value></Leq></Where></Query>";
camlQuery.ViewXml=”“;
如果没有帮助,请尝试添加视图标记

 camlQuery.ViewXml = "<View><Query><Where><Leq><FieldRef Name='Modified'/><Value Type='DateTime'><Today OffsetDays='-" + offset + "'/></Value></Leq></Where></Query></View>";
camlQuery.ViewXml=”“;

我添加了一个答案,如果有帮助,请告诉我