People have written about deploying various customizations and custom functionalities as features via
SharePoint Solution packages. I'm not going to go through it step by step here. As usual, I want to focus on the 'unusual' or 'gotcha' stuff when it comes to
SharePoint.
Assuming you already have your custom theme, feature.
xml, and the solution packaging files (manifest.
xml and the
ddf) ready, you can deploy the theme via the solution package, which adds your custom theme to /12/TEMPLATES/THEMES. Then you need to tell your site collection or web to actually use this new
custom theme. This is typically
accomplished in the
FeatureReceiver class so when you activate the feature, the theme is applied. There are of course other ways to do this. For example, you can write a simple console application to run on the
SharePoint WFE server to apply the theme.
SPWeb has a method
ApplyTheme() that allows you to change the web theme in the code.
public override void FeatureActivated(SPFeatureReceiverProperties properties) {SPSite site = properties.Feature.Parent as SPSite;if (site == null) {throw new SPException("This feature should only be activated on a Site Collection");}SPWeb rootweb = site.RootWeb;rootweb.MasterUrl = "MyNewUI.master"; rootweb.ApplyTheme("MyCustomTheme");rootweb.Update();}
The code works without any error and the master page is correctly applied to the root web when you activate the feature. However, the custom theme is not applied. What is wrong?
The problem is with the order of the last two methods on
SPWeb. It is necessary to call
SPWeb.Update() to commit the changes when you assign new values to many of the
pulbic properties of
SPWeb. However, calling Update() AFTER
ApplyTheme() somehow wipes out the change
ApplyTheme() makes. So in order for this to work, there cannot be an Update() call after
ApplyTheme() is called on the same instance of
SPWeb. The above code would work perfectly by simply switch the order of the two method calls:
................
rootweb.Update();rootweb.ApplyTheme("MyCustomTheme");
...............Some folks have mentioned that in order to apply a
custom theme from feature activation, there can not be an entry in \12\TEMPLATE\LAYOUTS\1033\
SPTHEMES.XML for the theme. I found this to be not true.
SPTHEMES.XML is for displaying the available themes on _layouts/
themeweb.
aspx for user to select. It has bearing on how a theme works or how it's applied. Therefore, you can either modify
SPTHEMES.XML in your
FeatureReceiver class or you don't have to. Adding an entry would allow user to see the theme applied listed on on _layouts/
themeweb.
aspx. That's all.
.