SPList 类
代表Microsoft SharePoint Foundation Web 网站上的列表。
继承层次结构
System.Object
Microsoft.SharePoint.SPSecurableObject
Microsoft.SharePoint.SPList
Microsoft.SharePoint.SPDocumentLibrary
Microsoft.SharePoint.SPIssueList
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Class SPList _
Inherits SPSecurableObject
用法
Dim instance As SPList
public class SPList : SPSecurableObject
备注
列表包含的项或行和列或包含数据的字段。Items属性返回的项的集合,在列表中,并且Fields属性列表中返回的字段的集合。为了提高性能,最佳做法是使用GetItem*方法之一从列表返回项筛选出的集合。
各种SPList属性、 ParentList属性和其他属性或Microsoft.SharePoint命名空间中类的方法返回列表集合从特定的上下文。否则,使用SPWeb或SPList类的Lists属性网站或列表的父列表的集合中返回一个SPListCollection object,表示列表的集合。使用索引器从集合中返回单个列表。例如,如果集合分配给名为collLists的变量中,使用 C# 中的collLists[index]或collLists(index) Visual Basic,其中index是集合,该列表的显示名称的列表中的索引号,或列表的 GUID。
示例
下面的代码示例返回并显示"ProjectedValue"字段中的值大于 500 指定列表中的项目。该示例假定存在包含标签控件的.aspx 页面。
此示例要求对Microsoft.SharePoint和Microsoft.SharePoint.Utilities命名空间的using指令 (在 Visual Basic 中的Imports )。
Dim siteCollection As SPSite = SPContext.Current.Site
Try
Dim list As SPList = siteCollection.AllWebs("Site_Name").Lists("List_Name")
Dim query As New SPQuery()
query.Query = "<Where><Gt><FieldRef Name='ProjectedValue'/>" + "<Value Type='Number'>500</Value></Gt></Where>"
Dim listItems As SPListItemCollection = list.GetItems(query)
Dim listItem As SPListItem
For Each listItem In listItems
Label1.Text += "Item: " + SPHttpUtility.HtmlEncode(listItem("Title").ToString()) +
"::" + "Value: " + SPHttpUtility.HtmlEncode(listItem("Investment").ToString()) +
"::" + "Calculated: " + SPHttpUtility.HtmlEncode(listItem("ProjectedValue").ToString()) + "<BR>"
Next listItem
Finally
siteCollection.Dispose()
End Try
SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where><Gt><FieldRef Name='ProjectedValue'/>" +
"<Value Type='Number'>500</Value></Gt></Where>";
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
Label1.Text += "Item: " +
SPHttpUtility.HtmlEncode(oListItem["Title"].ToString()) +
"::" + "Value: " +
SPHttpUtility.HtmlEncode(oListItem["Investment"].ToString()) +
"::" + "Calculated: " +
SPHttpUtility.HtmlEncode(oListItem["ProjectedValue"].ToString()) +
"<BR>";
}
}
After instantiating an SPQuery object, the example uses Collaborative Application Markup Language (CAML) to define criteria for the query, which is passed as a parameter in the GetItems method. For information about CAML, see Collaborative Application Markup Language.
备注
For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint.
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。