Export (0) Print
Expand All

SPList.GetItems Method (SPView)

Windows SharePoint Services 3

Returns a collection of list items from the list based on the specified view.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPListItemCollection GetItems(
	SPView view
)

Parameters

view
Type: Microsoft.SharePoint.SPView
An SPView object that represents the view.

Return Value

Type: Microsoft.SharePoint.SPListItemCollection
An SPListItemCollection object that represents the list items.

The following code example shows uses the GetItems method to return items from a list according to the specified view.

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

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

SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPView oListView = oList.Views["View_Name"];

SPListItemCollection collListItems = oList.GetItems(oListView);

foreach (SPListItem oListItem in colListItems)
{
    Label1.Text += 
        SPEncode.HtmlEncode(oListItem["Field1_Name"].ToString())
        + " -- " + 
        SPEncode.HtmlEncode(oListItem["Field2_Name"].ToString())
        + "<BR>";
}

Community Additions

ADD
Show:
© 2014 Microsoft