My Insights
Inherit Site Theme programmatically
The Microsoft.SharePoint.Utilities namespace contains a class called ThmxTheme which gives us some nice utility methods to interact with site themes in SharePoint 2010. Here is an example of how to automatically set the theme for a newly created SPWeb to be the same as the root web-
ThmxTheme.SetThemeUrlForWeb(newWeb, ThmxTheme.GetThemeUrlForWeb(newWeb.Site.RootWeb));
Do you know of a nicer way to inherit site themes? Please post a comment below.
UPDATE (09/09/10): An alternative way to do this-
ThmxTheme theme = ThmxTheme.Open(web.Site, "_catalogs/theme/MyTheme.thmx"); theme.ApplyTo(web, true);
5 Responses to Inherit Site Theme programmatically
Leave a Reply Cancel reply
Pages
What I'm Doing...
- Laundry or #EUSPHack 5 years ago I would've considered that choice a sad Friday night, but today I find it to be glorious. 16 hrs ago
- More updates...
Archives
- May 2012
- December 2011
- August 2011
- June 2011
- April 2011
- March 2011
- September 2010
- August 2010
- July 2010
- May 2010
- February 2010
- January 2010
- November 2009
- March 2009
- January 2009
- April 2008
- March 2008
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- March 2007
- February 2007
- December 2006
- October 2006
- September 2006
- August 2006
- June 2006
- May 2006
- April 2006
- March 2006
- December 2005
- September 2005
- August 2005
- June 2005
- April 2005
- March 2005
- February 2005
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- March 2004
- September 2003
- August 2003
- April 2003
Categories
- Chromium OS
- Internet Explorer 7
- Kwizcom
- Miscellaneous
- Movies
- MS Office
- Music
- Night on the Town
- Office 2007
- Outlook 2007
- Pictures
- Products/Shopping
- Recovered Entries (01/19/2005)
- Restaurants/Food
- Sharepoint 2007 ( MOSS / WSS )
- Sharepoint 2010 (SPS / Foundation)
- Tech
- The Law
- TV
- Uncategorized
- Video Games
- Vista
- Visual Studio 2010
- VMWARE
- VMWARE Server 2.0
- Website
- Windows Live
- Work
- XP





I cannot seem to get this code to function.
newWeb does not exist
@Justin – newWeb is just a variable name that refers to a SPWeb object that represents the web where you want to apply the new theme.
I understand that.
Currently I have newWeb = SPContext.Current.Web
This does not function on a new site being created, as it does not offically exist yet.
What do you have your variable set to?
@Justin – I ended up using a feature that is stapled to the GLOBAL template. Presumably you could also attach an event receiver to the new WebProvisioned event. Here is some sample code-
class ApplyTheme : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
base.FeatureActivated(properties);
using (var web = properties.Feature.Parent as SPWeb)
{
if (web != null)
{
ThmxTheme theme = ThmxTheme.Open(web.Site, “_catalogs/theme/Fraunhofer.thmx”);
theme.ApplyTo(web, true);
}
}
}
}
Thanks, I will give that a go.
I have attempted to use an event receiver on the web provisioned and the web was provisioned events receivers, with no success.