다음을 통해 공유


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

Syntax

'Declaration
<ClientCallableConstraintAttribute(Type := ClientCallableConstraintType.NotNull)> _
<ClientCallableAttribute> _
Public ReadOnly Property ViewFields As SPViewFieldCollection
    Get
'Usage
Dim instance As SPView
Dim value As SPViewFieldCollection

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

Property Value

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

Remarks

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

Examples

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.

Dim siteColl As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteColl.AllWebs("Site_Name")

Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("All Items")
Dim viewFields As SPViewFieldCollection = view.ViewFields

viewFields.Add("Created")

view.Update() 
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;
   collViewFields.Add("Created");

   oView.Update();
}

Note

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.

See Also

Reference

SPView Class

SPView Members

Microsoft.SharePoint Namespace