Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GetView Method

SPList.GetView Method

Windows SharePoint Services 3

Returns a view of the list based on the specified GUID.

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

public SPView GetView(
	Guid viewGuid


Type: System.Guid
The GUID that identifies the view.

Return Value

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

The following code example uses the GetView method to return a specified view for a list and passes this view as a parameter in the GetItems method in order to return and display items.

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 named Label1.

SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
Guid guidViewID = oList.Views["View_Name"].ID;
SPView oViewSrc = oList.GetView(guidViewID);
SPViewFieldCollection collViewFields = oViewSrc.ViewFields;
SPListItemCollection collItemsSrc = oList.GetItems(oViewSrc);

foreach (SPListItem oItemSrc in collItemsSrc)
    for (int intIndex=0; intIndex<collViewFields.Count; intIndex++)
        Label1.Text +=               SPEncode.HtmlEncode(oItemSrc[collViewFields[intIndex]].ToString()) 
         + " :: ";
    Label1.Text += "<BR>";

The ViewFields property gets the displayed fields in the list, which are then used in indexers for each list item.

Community Additions

© 2015 Microsoft