kev*_*een 7 c# sharepoint caml
我正在尝试通过CAML从SharePoint中提取列表,我希望按特定字段排序返回的列表.该字段是查找字段.当我将OrderBy设置为查找字段时,查询返回无序,如果我使用文本字段就可以了.
当我在编辑器中构建它时,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);
Run Code Online (Sandbox Code Playgroud)
其余的是一个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>
Run Code Online (Sandbox Code Playgroud)
无论出于何种原因,CAML查询工具都能正常工作,我的代码却没有.谁知道为什么?提前致谢.
编辑反映我实际测试的代码.我有一些代码值不正确.
您发布的代码示例与wireshark查询不匹配:
<Query><Where><Eq><FieldRef Name='paApproved' /><Value Type='Boolean'>1</Value></Eq></Where><OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy></Query>
应该:
<Where><Eq><FieldRef Name="paApproved" /><Value Type="Boolean">1</Value></Eq></Where><OrderBy><FieldRef Name="paState" Ascending="False" /></OrderBy>
您不需要这些<Query></Query>元素(请参阅此处的示例).
| 归档时间: |
|
| 查看次数: |
30528 次 |
| 最近记录: |