SPListItemCollectionPosition 类
支持分页的数据集、 存储列表的特定视图获取数据的第二页所需的状态。
继承层次结构
System.Object
Microsoft.SharePoint.SPListItemCollectionPosition
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Class SPListItemCollectionPosition
用法
Dim instance As SPListItemCollectionPosition
public class SPListItemCollectionPosition
示例
下面的代码示例使用SPListItemCollection类和SPQuery类的ListItemCollectionPosition属性返回一个SPListItemCollectionPosition对象存储有关的信息,其中结束的项时,集合中的每个数据页,其中显示 10 行组内的项的标题。本示例假定该列表是一个文档库或列表中启用的文件夹。
此示例要求using指令 (Imports Microsoft Visual Basic 中) 为Microsoft.SharePoint和Microsoft.SharePoint.Utilities的命名空间。
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim list As SPList = site.Lists("Announcements")
Dim query As New SPQuery()
query.RowLimit = 10
query.Query = "<OrderBy Override=\"TRUE\">" & _
"<FieldRef Name=\"FileLeafRef\" /></OrderBy>";
Dim i As Integer = 1
Do
Response.Write("<BR>Page: " & i & "<BR>")
Dim listItems As SPListItemCollection = list.GetItems(query)
Dim listItem As SPListItem
For Each listItem In listItems
Response.Write
(SPEncode.HtmlEncode(listItem("Title").ToString()) & _
"<BR>")
Next listItem
query.ListItemCollectionPosition = _
listItems.ListItemCollectionPosition
i += 1
Loop While Not (query.ListItemCollectionPosition Is Nothing)
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["Announcements"];
SPQuery oQuery = new SPQuery();
oQuery.RowLimit = 10;
oQuery.Query = "<OrderBy Override=\"TRUE\">" +
"<FieldRef Name=\"FileLeafRef\" /></OrderBy>";
int intIndex = 1;
do
{
Response.Write("<BR>Page: " + intIndex + "<BR>");
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
Response.Write(SPEncode.HtmlEncode(oListItem["Title"].ToString()) +
"<BR>");
}
oQuery.ListItemCollectionPosition =
collListItems.ListItemCollectionPosition;
intIndex++;
} while (oQuery.ListItemCollectionPosition != null);
备注
有关如何使用语言集成查询 (LINQ) 查询来检索SharePoint Foundation中的列表项的信息,请参阅Managing Data with LINQ to SharePoint。
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。