我试图通过CAML从SharePoint拉清单,我想列表中返回一个特定的字段排序。该字段是查找字段。当我将OrderBy设置为查找字段时,查询返回无序,如果我使用文本字段就没问题。当我在编辑器中建立它CAML查询SharePoint列表,以便通过查找字段
的U2U CAML查询生成器将返回此查询订购。
这里是我如何建立和执行查询的代码片段:
String baseQuery = "<Query><Where><Eq><FieldRef Name='paApproved' /><Value Type='Boolean'>1</Value></Eq></Where><OrderBy><FieldRef Name='paState' Ascending='True' LookupValue='TRUE' /></OrderBy></Query>";
qStates.Query = baseQuery;
SPListItemCollection byState = web.Lists["paUpdates"].GetItems(qStates);
剩下的就是一个for循环,分析收集和显示。如有必要,我可以发布。
这里是由CAML查询工具进行的SOAP调用,从我使用Wireshark的HTTP流刮掉它。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>paUpdates</listName>
<query>
<Query xmlns="">
<Where>
<Eq>
<FieldRef Name="paApproved" />
<Value Type="Boolean">1</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="paState" Ascending="False" />
</OrderBy>
</Query>
</query>
<viewFields>
<ViewFields xmlns="" />
</viewFields>
<queryOptions>
<QueryOptions xmlns="" />
</queryOptions>
</GetListItems>
</soap:Body>
</soap:Envelope>
无论出于什么原因CAML查询工具的工作原理,我的代码不会。有人知道为什么提前致谢。
编辑以反映我实际测试的代码。我有一些代码的值不正确。
你说得对。对不起,我正在测试一些东西。我使用“标题”来查看它是否会在文本字段上排序,而不是查找。我使用的代码确实有“paState”作为字段,并且不起作用。我剪下并粘贴了错误的版本。它将排序在文本字段上,但现在在查找字段上。 – kevingreen 2011-02-07 16:08:51