c# - 对 SharePoint 列表的 CAML 查询返回整个集合

标签 c# sharepoint-2010 caml

我遇到了一个问题,如果我在 C# 中执行 CAML 查询,我的 ListItemCollection 包含整个列表。这是一个片段 我清理过的代码也许你可以看到我做错了什么。 在调试时,我发现生成的 XML 是我期望从文件中读取的值。似乎有一个问题 实际执行查询并加载结果。我在这里完成的步骤对我来说似乎不正确,我觉得我错过了一步。

using Microsoft.SharePoint.Client;
...
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(user, password, domain);
ClientContext clientContext = new ClientContext(uri);
clientContext.Credentials = credentials;
List list = clientContext.Web.Lists.GetByTitle(listName);
//read line of input from file and save to string[]
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<Query><Where><And><Eq><FieldRef Name=\"Entity\" /><Value Type=\"Text\">" + columns[2].Trim() + "</Value></Eq><And><Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">" + columns[0].Trim() + "</Value></Eq><Eq><FieldRef Name=\"Section\" /><Value Type=\"Text\">" + columns[1].Trim() + "</Value></Eq></And></And></Where></Query>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();

最佳答案

在 SharePoint CSOM 中,CamlQuery.ViewXml property 的根元素是<View> ,例如:

public CamlQuery CreateInventoryQuery(string searchSku)
{
   var qry = new CamlQuery();
   qry.ViewXml =
      @"<View>
         <Query>
          <Where>
            <BeginsWith>
              <FieldRef Name='SKU' />
              <Value Type='Text'>" + searchSku + @"</Value>
            </BeginsWith>
          </Where>
        </Query>
       </View>";
   return qry;
}

引用资料

Using the Client Object Model

关于c# - 对 SharePoint 列表的 CAML 查询返回整个集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22847269/

相关文章:

sharepoint - 如何将我的代理凭据传递给 SharePoint 客户端上下文对象...? (SharePoint 客户端对象模型)

sharepoint - CAML 是查询 MOSS 的唯一方法吗?

sharepoint - 如何对 splititemcollection 中的项目进行排序?

c# - 如何避免多次注册事件

c# - 使用数据库而不是内存存储身份服务器 4

sharepoint-2010 - SharePoint 2010 工作流程未启动

sharepoint - 在sharepoint客户端中开发webpart

sharepoint-2010 - SharePoint 2010 - 错误阅读列表项 "Cannot complete this action. Please try again."

c# - 从头开始创建面向方面的属性/方法

c# - WCF 数据对象接收进度