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); }
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); }
public static void InheritTopSiteBranding(SPWeb currentWeb, SPWeb rootWeb, SPSite site, string webAppRelativePath) { var catalogMasterPage = CustomBranding.DeployComposedLookSiteNavEventReceiver_catalogMasterPage__catalogs_masterpage_; var masterPageName = CustomBranding.BrandingHelper_RemoveMasterPage_Custom_SP2013_master; var masterPageNameSiteNav = CustomBranding.BrandingHelper_RemoveMasterPage_Custom_SP2013CustomSiteNav_master; //if master page is applied change current spweb //need to check because must apply theme .spcolor from file path; need consistent results for end user if (rootWeb.MasterUrl == webAppRelativePath + catalogMasterPage + masterPageName || rootWeb.MasterUrl == webAppRelativePath + catalogMasterPage + masterPageNameSiteNav) { var themeUrl = new SPFieldUrlValue(); var fontUrl = new SPFieldUrlValue(); currentWeb.MasterUrl = rootWeb.MasterUrl; currentWeb.CustomMasterUrl = rootWeb.MasterUrl; themeUrl.Url = webAppRelativePath + CustomBranding.InheritBranding_WebProvisioned__catalogs_theme_15_Custom_spcolor; fontUrl.Url = webAppRelativePath + CustomBranding.InheritBranding_WebProvisioned__catalogs_theme_15_fontscheme002_spfont; currentWeb.SiteLogoUrl = webAppRelativePath + CustomBranding.InheritBranding_WebProvisioned__catalogs_masterpage_Custom_SP2013_LOGO_png; currentWeb.Update(); //apply font and color to current SPWeb var themeFile = rootWeb.GetFile(themeUrl.Url); var fontSchemeFile = rootWeb.GetFile(fontUrl.Url); var customLook = CustomBranding.InheritBranding_WebProvisioned_Custom_SP2013_ComposedLook; var theme = SPTheme.Open(customLook, themeFile, fontSchemeFile); theme.ApplyTo(currentWeb, true); } }
public static void RemoveComposedLookTopSite(SPWeb topWeb, SPSite site, String webAppRelativePath) { var themeUrl = new SPFieldUrlValue(); var fontUrl = new SPFieldUrlValue(); var logoUrl = new SPFieldUrlValue(); //SPFieldUrlValue bgImageURL = new SPFieldUrlValue(); var masterUrl = new SPFieldUrlValue(); //if paths incorrect, files don't delete correct theme is not applied masterUrl.Url = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__catalogs_masterpage_seattle_master; themeUrl.Url = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__catalogs_theme_15_palette001_spcolor; fontUrl.Url = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__catalogs_theme_15_fontscheme002_spfont; logoUrl.Url = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__layouts_15_images_siteicon_png; //these paths must be web relative with serverrelative url 1-28 changed for root topWeb.CustomMasterUrl = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__catalogs_masterpage_seattle_master; topWeb.MasterUrl = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__catalogs_masterpage_seattle_master; topWeb.SiteLogoUrl = webAppRelativePath + CustomBranding.BrandingHelper_RemoveComposedLookTopSite__layouts_15_images_siteicon_png; topWeb.Update(); var themeFile = topWeb.GetFile(themeUrl.Url); var fontSchemeFile = topWeb.GetFile(fontUrl.Url); var theme = SPTheme.Open("Office", themeFile, fontSchemeFile); theme.ApplyTo(topWeb, true); //next two lines possibly redundant //topWeb.ApplyTheme(themeURL.Url.ToString(), fontURL.Url.ToString(), null, true); //topWeb.Update(); // Enumerate through each site and apply out of box branding. foreach (SPWeb web in site.AllWebs) { if (web.Url == topWeb.Url) { continue; } web.CustomMasterUrl = masterUrl.Url; web.MasterUrl = masterUrl.Url; web.SiteLogoUrl = logoUrl.Url; theme.ApplyTo(web, true); web.Update(); //next two lines possibly redundant // web.ApplyTheme(themeURL.Url.ToString(), fontURL.Url.ToString(), null, true); } var list = topWeb.Lists["Composed Looks"]; var currentLooks = list.GetItems(); foreach (SPListItem itemUpdate in currentLooks.Cast <SPListItem>().Where(itemUpdate => itemUpdate.Name == "Current")) { itemUpdate["MasterPageUrl"] = masterUrl; itemUpdate["ThemeUrl"] = themeUrl; itemUpdate["FontSchemeUrl"] = fontUrl; itemUpdate["ImageUrl"] = null; itemUpdate.Update(); } }
public static SPTheme ApplyThemeToRootWeb(SPWeb topWeb, String webAppRelativePath, string customLookCustom, SPFieldUrlValue themeUrl, SPFieldUrlValue fontUrl) { //order of this method important //3. apply comp look 4. update current in comp look list var themeFile = topWeb.GetFile(themeUrl.Url); var fontSchemeFile = topWeb.GetFile(fontUrl.Url); var theme = SPTheme.Open(customLookCustom, themeFile, fontSchemeFile); theme.ApplyTo(topWeb, true); return(theme); }
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; }