Cette documentation est archivée et n’est pas conservée.

SPList, classe (Microsoft.SharePoint)

Windows SharePoint Services 3
Represents a list on a SharePoint Web site.

Espace de noms : Microsoft.SharePoint
Assembly : Microsoft.SharePoint (dans microsoft.sharepoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public class SPList : ISecurableObject

A list consists of items or rows, and columns or fields, that contain data. Use the Items property to return the collection of items in the list, and use the Fields property to return the collection of fields in the list.

Various List properties, ParentList properties, and other properties or methods for classes in the Microsoft.SharePoint namespace return a list or collection of lists from a specific context. Otherwise, use the Lists property of either the SPWeb or SPList class to return an SPListCollection object that represents either the collection of lists in a site or the collection of parent lists for a list. Use an indexer to return a single list from the collection. For example, if the collection is assigned to a variable named collLists, use collLists[index] in C#, or collLists(index) in Visual Basic 2005, where index is the index number of the list in the collection, the display name of the list, or the GUID of the list.

The following code example returns and displays items from a specified list where values in the "ProjectedValue" field are greater than 500.

The example assumes the existence of an .aspx page that contains a label control.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

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: " + 
        SPEncode.HtmlEncode(oListItem["Title"].ToString()) + 
        "::" + "Value: " +   
        SPEncode.HtmlEncode(oListItem["Investment"].ToString()) +
        "::" + "Calculated: " + 
        SPEncode.HtmlEncode(oListItem["ProjectedValue"].ToString()) + 

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 Schémas principaux du langage CAML (Collaborative Application Markup Language).

In addition, the example uses indexers on each list item to return values from the specified fields.

Les membres statiques publics de ce type (Shared en Visual Basic) sont sécurisés au niveau des threads. Il n'est pas garanti que les membres d'instance soient sécurisés au niveau des threads.