gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:19:15 26 4
gpt4 key购买 nike

我遇到了一个问题,如果我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com