deploy new v4 theme as feature
Creating a custom theme
- Goto C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\Lists\themes
- Copy one of the OOTB themes into your working folder e.g. c:\work and rename it to MyTheme.thmx
- Open this file in Microsoft Theme Builder, name it appropriately, in this case 'MyTheme' and change the colors to suit your needs and save the file.
Creating a SharePoint Project
- Create an 'Empty SharePoint Project' called 'MyCustomTheme'
- In VS, right click on project > Add > New Item.. > Module , named 'ModuleMyTheme'
- Drag drop the .thmx file from the file system into the 'ModuleMyTheme' in VS
- Delete the sample.txt file from the module folder. The resultant VS solution explorer should as follows..
Modifying the elements.xml
The xml that is generated after the above steps is
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ModuleMyTheme">
<File Path="ModuleMyTheme\MyTheme.thmx" Url="ModuleMyTheme/MyTheme.thmx" />
</Module>
</Elements>
The source of the thmx file is represented by File > Path, which is the location from the feature folder.
The destination should be the theme folder under _catalogs i.e. '_catalogs/theme/MyTheme.thmx'. This has to be added as the URL attribute in module tag plus the URL attribute in the File tag. The final xml looks like the following..
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ModuleMyTheme" Url="_catalogs/theme">
<File Path="ModuleMyTheme\MyTheme.thmx" Url="MyTheme.thmx" />
</Module>
</Elements>
Time to deploy – right-click the project and select deploy.
Once deployed, navigate to the site > Site Actions > Site Settings > Look and Feel > Site Themes, you will find your custom theme deployed.
Download Code here
You may also be interested in the following..
Apply theme programmatically Sharepoint 2010 sample usage: if you wanted to apply the newly deployed theme using a feature reciever
THMX theme reference


Hi,
ReplyDeleteif I download your sample file, works great, I can add my THMX files, but I cant rename project and/or feature, otherwise themes will disappear.
Apparently it is somehow locked to these names. I tried to search whole project after rename and "MyCustomTheme" and/or "Feature1" could be found.
Strange thing. Any hint ?
thank you for that
Tomas
This didn't work for me until I added the Type and IgnoreIfAlreadyExists attributes to my file element. Here is what it looks like with those:
ReplyDeleteAttribute Type="GhostableInLibrary" needs to be added to the File element to be able to view theme files in the document library. Open in explorer view and you will see them added, but not displayed in the library without that tag.
ReplyDelete