SPWeb.ApplyTheme Method
Applies a theme to a website.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Parameters
- strNewTheme
- Type: System.String
The template ID of the new theme that is specified in the SpThemes.xml file of the \\ProgramFiles\Common Files\Microsoft Shared\web server extensions\14\Template\Layouts\1033 folder.
Caution
|
|---|
|
Use this method only when the UI is in backward compatibility mode (SPWeb.UIVersion = 3). |
This method sets the Theme property to the name of the theme specified by strNewTheme.
The following code example applies a specified theme to a site in the current site collection.
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL")) { oWebsite.ApplyTheme("Theme_ID"); }
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. |
What to do when UIVersion = 4
Since this function only works when UIVersion = 3, you should use the ThmxTheme class found in Microsoft.SharePoint.Utilities, in particular the ThmxTheme.ApplyTo method - http://msdn.microsoft.com/en-us/library/ee659982.
- 5/10/2012
- Eric Overfield
Caution
Note