0 out of 2 rated this helpful - Rate this topic

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

An SPView object that represents the view.

Return Value

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>";
}

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.