views:

726

answers:

2

Up to this point we have not yet needed a new masterpage for our SharePoint Site Definition. We have a theme that some of our customers will use depending on their corporate SharePoint branding.

Currently I change the 'SiteLogoUrl' in my 'FeatureReceiver' on the 'FeatureActivated' event using the following code.

    public override void FeatureActivated(SPFeatureReceiverProperties properties) {
        AddThemeToSpThemes(THEME_ID, THEME_NAME, THEME_DESC, THEME_IMAGE, THEME_IMAGE);
        SPWeb site = properties.Feature.Parent as SPWeb;
        if (site != null) {
            site.AllowUnsafeUpdates = true;
            site.SiteLogoUrl = site.Url + "images/thLogo.gif";
            site.Update();
        }
    }

FeatureActivated is not the best event to trigger on, I would prefer a theme applied event but I can't seem to find one. Perhaps I am not approaching this correctly.

A: 

Hi,

Your code should work just fine. The FeatureActivated/FeatureDeactivating methods are the places where you can add custom code.

Out of curiosity, why did you think that you're not using the correct event? There aren't too many events in sharepoint, and the theme functionality is quite limited. The CSS files are extensive, but the .net side is small.

My guess is that you want to force the SiteLogoUrl, even if the theme changes (so your customers could choose a funky theme for their site, while keeping the logo).

Also, a masterpage is not a theme, so I'm not sure why you said, "Up to this point we have not yet needed a new masterpage for our SharePoint Site Definition".

Cheers,

Matt.

Matt Lynch
Activating a feature and applying a theme are two completely different things. I would like to change the image when a theme is applied.
Cube Pirate
+1  A: 

Applying a theme doesn't have an event.

You may be doing this backwards (although the obvious way). How about having your feature receiver activate the theme programmatically, as well as setting your logo?

Note you can store the currently applied theme in the SPWeb's property bag - see this for an example, but storing the current master pages before changing them.

It is worth considering using the Alternate CSS instead of Themes too. That can also be set on you SPWeb object (AlternateCssURL).

Andy Burns