Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ViewStyles property
Collapse the table of content
Expand the table of content

SPWeb.ViewStyles property

Gets the collection of view styles for the website.

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

public SPViewStyleCollection ViewStyles { get; }

Property value

Type: Microsoft.SharePoint.SPViewStyleCollection
An SPViewStyleCollection object that represents the view styles.

The following code example uses the ViewStyles property to return the collection of view styles for a site and it applies a Newsletter style (15) to a view for a list in the specified site.

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
    SPViewStyleCollection collViewStyles = oWebsite.ViewStyles;
    SPViewStyle oViewStyle = collViewStyles.StyleByID(15);
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];

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.

© 2015 Microsoft