Beispiel #1
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb Web = properties.Feature.Parent as SPWeb;

            Web.MasterUrl       = Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/seattle.master";
            Web.CustomMasterUrl = Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/seattle.master";
            Web.SiteLogoUrl     = "";
            Web.Update();

            SPFile colorPaletteFile = Web.GetFile(Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/theme/15/Palette001.spcolor");

            if (null == colorPaletteFile || !colorPaletteFile.Exists)
            {
                throw new Exception("colorPaletteFile");
            }

            SPFile fontSchemeFile = Web.GetFile(Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/theme/15/SharePointPersonality.spfont");

            if (null == fontSchemeFile || !fontSchemeFile.Exists)
            {
                throw new Exception("fontSchemeFile");
            }

            SPTheme theme = SPTheme.Open("SharePointDefault", colorPaletteFile, fontSchemeFile);

            theme.ApplyTo(Web, true);
        }
Beispiel #2
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb Web = properties.Feature.Parent as SPWeb;

            Web.MasterUrl       = Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/Abastecimiento2013.master";
            Web.CustomMasterUrl = Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/Abastecimiento2013.master";
            Web.SiteLogoUrl     = Web.Site.RootWeb.ServerRelativeUrl + "/Style%20Library/Abastecimiento/img/Logos/SiteLogo.png";
            Web.Update();

            SPFile colorPaletteFile = Web.GetFile(Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/theme/15/Abastecimiento2013.spcolor");

            if (null == colorPaletteFile || !colorPaletteFile.Exists)
            {
                throw new Exception("colorPaletteFile");
            }

            SPFile fontSchemeFile = Web.GetFile(Web.Site.RootWeb.ServerRelativeUrl + "/_catalogs/theme/15/SharePointPersonality.spfont");

            if (null == fontSchemeFile || !fontSchemeFile.Exists)
            {
                throw new Exception("fontSchemeFile");
            }

            SPTheme theme = SPTheme.Open("Abastecimiento2013", colorPaletteFile, fontSchemeFile);

            theme.ApplyTo(Web, true);
        }
Beispiel #3
0
        public static void ApplyComposedLook(SPTheme theme, SPWeb currentWebSite)
        {
            //old SPWeb topWeb, SPWeb currentWebSite, String customLook, SPFieldUrlValue masterURL, SPFieldUrlValue themeURL, SPFieldUrlValue fontURL


            //SPFile themeFile = topWeb.GetFile(themeURL.Url);
            //SPFile fontSchemeFile = topWeb.GetFile(fontURL.Url);
            //SPTheme theme = SPTheme.Open(customLook, themeFile, fontSchemeFile);
            theme.ApplyTo(currentWebSite, true);
            currentWebSite.Update();
            ////redundant
            // currentWebSite.ApplyTheme(themeURL.Url.ToString(), fontURL.Url.ToString(), null, true);
        }
        private void ApplyComposedLookUnderWeb(object modelHost, WebModelHost typedModelHost,
                                               ComposedLookItemLinkDefinition typedDefinition)
        {
            var web     = typedModelHost.HostWeb;
            var rootWeb = typedModelHost.HostWeb.Site.RootWeb;

            var siteRelativeUrl = web.Site.ServerRelativeUrl;

            var composedLookName = typedDefinition.ComposedLookItemName;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = web,
                ObjectType       = typeof(SPWeb),
                ObjectDefinition = typedDefinition,
                ModelHost        = modelHost
            });

            var composedLookList = web.GetCatalog(SPListTemplateType.DesignCatalog);
            var items            = composedLookList.GetItems(new SPQuery
            {
                Query    = CamlQueryUtils.WhereItemByFieldValueQuery("Name", composedLookName),
                RowLimit = 1
            });
            var targetComposedLookItem = items.Count > 0 ? items[0] : null;

            if (targetComposedLookItem == null)
            {
                throw new SPMeta2Exception(string.Format("Can't find composed look by name: [{0}]", composedLookName));
            }

            var name = ConvertUtils.ToString(targetComposedLookItem["Name"]);

            var masterPageUrl = GetUrlValue(targetComposedLookItem, "MasterPageUrl");

            if (!string.IsNullOrEmpty(masterPageUrl))
            {
                var targetMasterPageUrl = masterPageUrl;

                if (SPUrlUtility.IsUrlFull(masterPageUrl))
                {
                    targetMasterPageUrl = web.GetServerRelativeUrlFromUrl(masterPageUrl);
                }

                web.CustomMasterUrl = targetMasterPageUrl;
                web.MasterUrl       = targetMasterPageUrl;

                web.Update();
            }

            var themeUrl      = GetUrlValue(targetComposedLookItem, "ThemeUrl");
            var fontSchemeUrl = GetUrlValue(targetComposedLookItem, "FontSchemeUrl");
            var imageUrl      = GetUrlValue(targetComposedLookItem, "ImageUrl");

            var    themeFile = rootWeb.GetFile(themeUrl);
            SPFile fontFile  = null;

            if (!string.IsNullOrEmpty(fontSchemeUrl))
            {
                fontFile = rootWeb.GetFile(fontSchemeUrl);
            }

            SPTheme theme = null;

            if (!string.IsNullOrEmpty(imageUrl))
            {
                theme = SPTheme.Open(name,
                                     themeFile,
                                     fontFile != null && fontFile.Exists ? fontFile : null,
                                     new Uri(imageUrl));
            }
            else
            {
                theme = SPTheme.Open(name,
                                     themeFile,
                                     fontFile != null && fontFile.Exists ? fontFile : null);
            }

            theme.ApplyTo(web, false);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = web,
                ObjectType       = typeof(SPWeb),
                ObjectDefinition = typedDefinition,
                ModelHost        = modelHost
            });

            // cirrent web was updated by theme engine
            // http://ehikioya.com/apply-themes-to-sharepoint/
            typedModelHost.ShouldUpdateHost = false;
        }