Example #1
0
        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite siteCollection = properties.Feature.Parent as SPSite;

            if (siteCollection != null)
            {
                SPWeb  topLevelSite       = siteCollection.RootWeb;
                String WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }
                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    if (!site.WebTemplate.Contains("APP"))
                    {
                        var pubWeb = PublishingWeb.GetPublishingWeb(site);
                        var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(site);
                        webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.Update();
                        pubWeb.Update();
                        site.MasterUrl       = WebAppRelativePath + "_catalogs/masterpage/seattle.master";
                        site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/seattle.master";
                        site.SiteLogoUrl     = "";
                        site.Update();
                    }
                }
            }
        }
        /// <summary>
        /// A site was provisioned.
        /// </summary>
        public override void WebProvisioned(SPWebEventProperties properties)
        {
            base.WebProvisioned(properties);
            SPSite siteCollection = properties.Web.Site;
            SPWeb  subSite        = properties.Web;

            if (!subSite.WebTemplate.Contains("APP"))
            {
                Guid sitePublishingGuid = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
                Guid webPublishingGuid  = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb");

                EnsureSiteFeatureActivated(sitePublishingGuid, siteCollection);
                EnsureWebFeatureActivated(webPublishingGuid, siteCollection, subSite);

                var pubWeb = PublishingWeb.GetPublishingWeb(subSite);
                var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(subSite);
                webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.InheritFromParentWeb;
                webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                webNavigationSettings.Update();
                pubWeb.Update();

                subSite.MasterUrl       = siteCollection.RootWeb.MasterUrl;
                subSite.CustomMasterUrl = siteCollection.RootWeb.CustomMasterUrl;
                subSite.SiteLogoUrl     = siteCollection.RootWeb.SiteLogoUrl;
                subSite.Update();
            }
        }
Example #3
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite siteCollection = properties.Feature.Parent as SPSite;

            if (siteCollection != null)
            {
                SPWeb topLevelSite = siteCollection.RootWeb;

                Guid sitePublishingGuid = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
                Guid webPublishingGuid  = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb");

                if (siteCollection.Features[sitePublishingGuid] == null)
                {
                    siteCollection.Features.Add(sitePublishingGuid);
                }
                String WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }

                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    if (!site.WebTemplate.Contains("APP"))
                    {
                        if (site.Features[webPublishingGuid] == null)
                        {
                            site.Features.Add(webPublishingGuid);
                        }
                        var pubWeb = PublishingWeb.GetPublishingWeb(site);
                        var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(site);
                        webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.Update();
                        pubWeb.Update();
                        site.MasterUrl       = WebAppRelativePath + "_catalogs/masterpage/RivernetTeamSite.master";
                        site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/RivernetTeamSite.master";
                        site.SiteLogoUrl     = WebAppRelativePath + "_layouts/15/images/RiverStonelogotransparent.png";
                        site.Update();
                    }
                }
            }
        }