SPView.ViewFields Property

Gets the view fields that are used in the view.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

[ClientCallableConstraintAttribute(Type = ClientCallableConstraintType.NotNull)]
public SPViewFieldCollection ViewFields { get; }

Property Value

Type: Microsoft.SharePoint.SPViewFieldCollection
An SPViewFieldCollection object that represents the view fields.

For more information about view fields, see the ViewFields element.

The following code example uses the ViewFields property to return the collection of view fields in the All Items view of a list and adds a new view field to the collection.

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
   SPList oList = oWebsite.Lists["List_Name"];
   SPView oView = oList.Views["All Items"];
   SPViewFieldCollection collViewFields = oView.ViewFields;


Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.