Expand Minimize
This topic has not yet been rated - Rate this topic

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"];
    oView.ApplyStyle(oView);
    oView.Update();
}
Note 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.

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.