Share via


SPViewStyleCollection Class

Represents a collection of SPViewStyle objects.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPViewStyleCollection

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

Syntax

'Declaration
<SubsetCallableTypeAttribute> _
Public Class SPViewStyleCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPViewStyleCollection
[SubsetCallableTypeAttribute]
public class SPViewStyleCollection : SPBaseCollection

Remarks

View styles are defined in \\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL\XML\VWSTYLES.XML.

Use the ViewStyles property of the SPWeb class to return the collection of view styles for a site. Use an indexer to return a single view style from the collection. For example, if the collection is assigned to a variable named collViewStyles, use collViewStyles[index] in C#, or collViewStyles(index) in Visual Basic, where index is the index number of the view style in the collection.

Examples

The following code example applies a Boxed style (13) to a view for a list in the specified site.

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim vwStyles As SPViewStyleCollection = site.ViewStyles

Dim vwStyle As SPViewStyle = vwStyles.StyleByID(13)

Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("View_Name")

view.ApplyStyle(vwStyle)

view.Update()
SPSite oSiteCollection = SPContext.Current.Site;
    using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
    {
        SPViewStyleCollection collViewStyles = oWebsite.ViewStyles;

        SPViewStyle oViewStyle = collViewStyles.StyleByID(13);
        SPList oList = oWebsite.Lists["List_Name"];
        SPView oView = oList.Views["View_Name"];
        oView.ApplyStyle(oViewStyle);
        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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

SPViewStyleCollection Members

Microsoft.SharePoint Namespace