Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Feature setting Masterpage & CSS doesn't work when included in SiteTemplate - but does work when activated manually

$
0
0

Hi,

I'm experiencing a strange behaviour recently. I wrote a feature with an EventReceiver that sets the masterpage and alternate css file for the current spweb it is activated for. When I activate that feature manually it works like expected. But if I include the same feature in a SiteTemplate and it is called during site-creation, it doesn't work. I debugged it and stepped through it. As far as I can tell everything looks right. It sets the masterpage and css file like it should and throws no error. But when the site loads in the end, it suddenly still uses the v4.master and no alternateCSS. How can that be?

If I deactivate the feature then manually and activate it again, it works...

Here's the feature:

		const string masterPage = MyOfficeProcess.master";
        const string searchMasterPage = "MyMinimal.master";
        const string alternateCss = "MyOfficeAlternateProcess.css";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;

            using (SPWeb topLevelSite = web.Site.RootWeb)
            {
                string relativePath = topLevelSite.ServerRelativeUrl;
                if (!relativePath.EndsWith("/"))
                {
                    relativePath += "/";
                }

                if (web.WebTemplate == "SRCHCENTERLITE" || web.WebTemplate == "SRCHCEN" || web.WebTemplate == "SRCHCENTERFAST")
                {
                    web.CustomMasterUrl = relativePath + "_catalogs/masterpage/" + searchMasterPage;
                }
                else
                {
                    web.MasterUrl = relativePath + "_catalogs/masterpage/" + masterPage;
                    web.CustomMasterUrl = relativePath + "_catalogs/masterpage/" + masterPage;
                }

                web.AlternateCssUrl = relativePath + "Style Library/My/" + alternateCss;
                web.UIVersion = 4;
                web.Update();
            }
        }


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>