SharePoint CAML Query小结

  1. CAML的结构。

<View Type="HTML" Name="Summary">

<ViewBody ExpandXML="TRUE">

<![CDATA[ <p><SPAN class=DocTitle><ows:Field Name="Title"/></SPAN>

(<ows:Field Name="Author"/>, <ows:Field Name="Modified"/>)

<ows:Limit><Field Name="Body"/></ows:Limit>

</p> ]]>

</ViewBody>

<Query>

<Where>

<Geq>

<FieldRef Name="Expires"/>

<Value Type="DateTime">

<Today/>

</Value>

</Geq>

</Where>

<OrderBy>

<FieldRef Name="Modified"/>

</OrderBy>

</Query>

<ViewFields>

<FieldRef Name="Summary"/>

<FieldRef Name="Author"/>

<FieldRef Name="Modified"/>

<FieldRef Name="Body"/>

</ViewFields>

</View>

 

可以在这个页面查看更详细的内容:

https://msdn.microsoft.com/en-us/library/office/ms438338.aspx

在这个页面上可以通过点击Parent Elements和Child Elements查看它可以包含的子元素和父元素。

SharePoint CAML Query小结

 

  1. 如何通过CAML查询一个View里面的数据。

服务器端的API支持输入View的ID:

https://msdn.microsoft.com/en-us/library/ms434064(v=office.15).aspx

SharePoint CAML Query小结

 

客户端的API则不支持:

https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.list.getitems.aspx

SharePoint CAML Query小结

需要用如下的方法进行查询:

Public
ListItemCollection
GetSPItems(listName, viewName){

 

ClientContext context = new
ClientContext("http://SiteUrl");

 

List list1 = context.Web.Lists.GetByTitle(listName);

 

View view = list1.Views.GetByTitle(viewName);

clientContext.Load(view);

clientContext.ExecuteQuery();

CamlQuery query = new
CamlQuery();

camlQuery.ViewXml = view.ViewQuery;

ListItemCollection items = announcementsList.GetItems(query);

 

context.Load(items);

context.ExecuteQuery();

retun items;

 

}

 

//Example of usage:

 

ListItemCollection listItems = GetSPItems("Tasks", "My Tasks");

 

 

 

上一篇:Unable to make the session state request to the session state server处理


下一篇:mysqldump 备份数据和恢复