5 February 2009 0 Comments

How to create a feature receiver that update a theme

Pre request: · Windows Server 2003 SP1 or above · Visual Studio 2008 Pro or above · Visual Studio Extension for SharePoint 1.3 CTP or later Steps: Start Visual Studio Create a SharePoint project using Empty template · =>File=>New=>Project · Visual C#=>SharePoint=>Empty · Type name as MyThemeFeature · Select FullTrust(Deploy to GAC) on the Select Trust Level popup window · =>OK Extract the Public Key token · Open Visual Studio Command Prompt · Go to the folder MyThemeFeatureProperties folder · Run Sn –p MyTheamFeature.snk > publicKey.snk · Run Sn –t publicKey.snk > Token.txt · Open Token.txt · Copy the public key token Create a New Feature with the event receiver · Switch to WSP view · Click refresh button so that MyThemeFeature is showing on the root note · Click create new feature button · On the Feature Scope Settings popup, select Add feature receiver, =>OK · Rename Feature1 to MyThemeFeature · Open feature.xml file · Inside feature.xml file, rename the title from feature1 to MyThemeFeature · Add ReceiverAssembly and ReceiverClass attribute so that the feature.xml file now looks like this: (the PublicKeyToken should be from the Token.txt file you copied before.) <?xml version=”1.0” encoding=”utf-8”?> <Feature Id=”b3c387b3-5f74-4054-bb70-8b45c7549afa” Title=”MyThemeFeature” Scope=”Web” Version=”1.0.0.0″ Hidden=”FALSE” DefaultResourceFile=”core” xmlns=”http://schemas.microsoft.com/sharepoint/” ReceiverAssembly=” MyThemeFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5″ ReceiverClass=” MyThemeFeature. FeatureReceiver1″ > <ElementManifests /> </Feature> Edit event receiver to use your theme · Open FeatureReceiver1.cs file · Modify the FeatureActivated and FeatureDeactivating methods as the following: public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; web.ApplyTheme(“YourThemeName”); } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; web.ApplyTheme(“none”); } · You need to replace the above “YourThemeName” with the them name you want. For example “Jet” Deploy and test your solution · Right click on MyThemeFeature project and select Deploy · Browser to your site

Go here to see the original: 
How to create a feature receiver that update a theme

If you liked this post, buy me a Coffee.

Leave a Reply