CAML 查询到 SharePoint 列表返回整个集合 [英] CAML Query to SharePoint list returns entire set
问题描述
我遇到了一个问题,如果我在 C# 中执行 CAML 查询,我的 ListItemCollection 包含整个列表.这是一个片段我清理过的代码也许你可以看到我做错了什么.在调试时,我发现生成的 XML 正是我对从文件中读取的值所期望的.好像有问题实际执行查询并加载结果.我在这里执行的步骤对我来说似乎不正确,我觉得我错过了一步.
I've been running into an issue where if I execute a CAML query in C#, my ListItemCollection contains the entirety of the list. Here is a snippet of my scrubbed code maybe you can see what I've done wrong. While debugging, I've found that that the XML generated is what I expected with the values read from a file. There seems to be an issue with actually doing the query and loading the results. The steps I've done to do that here don't seem correct to me, I feel like I'm missing a step.
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 属性是
,例如:
In SharePoint CSOM the root element for CamlQuery.ViewXml property is <View>
, for example:
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;
}
参考文献
这篇关于CAML 查询到 SharePoint 列表返回整个集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!