Beispiel #1
0
 private void ResetChildWebs(SPWeb web, string themesUrlForWeb)
 {
     foreach (SPWeb childWeb in web.Webs)
     {
         ThmxTheme.SetThemeUrlForWeb(childWeb, themesUrlForWeb);
         if (childWeb.Webs.Count > 0)
         {
             ResetChildWebs(childWeb, themesUrlForWeb);
         }
         childWeb.Dispose();
     }
 }
Beispiel #2
0
 private void UpdateInheritingWebs(SPWeb web, string oldThemesUrlForWeb, string newThemesUrlForWeb)
 {
     foreach (SPWeb childWeb in web.Webs)
     {
         string themesUrlForWeb = ThmxTheme.GetThemeUrlForWeb(childWeb);
         if (!string.IsNullOrEmpty(themesUrlForWeb) && themesUrlForWeb.ToLower() == oldThemesUrlForWeb.ToLower())
         {
             ThmxTheme.SetThemeUrlForWeb(childWeb, newThemesUrlForWeb);
         }
         if (childWeb.Webs.Count > 0)
         {
             UpdateInheritingWebs(childWeb, oldThemesUrlForWeb, newThemesUrlForWeb);
         }
         childWeb.Dispose();
     }
 }
Beispiel #3
0
        private void ResetSPTheme(SPWeb web, bool resetChildren)
        {
            try
            {
                // Store some variables for later use
                string tempFolderName   = Guid.NewGuid().ToString("N").ToUpper();
                string themedFolderName = SPUrlUtility.CombineUrl(web.Site.ServerRelativeUrl, "/_catalogs/theme/Themed");
                string themesUrlForWeb  = ThmxTheme.GetThemeUrlForWeb(web);

                if (string.IsNullOrEmpty(themesUrlForWeb))
                {
                    Logger.WriteWarning("The web {0} does not have a theme set and will be ignored.", web.Url);
                    return;
                }
                if (!web.IsRootWeb)
                {
                    string themesUrlForParentWeb = ThmxTheme.GetThemeUrlForWeb(web.ParentWeb);
                    if (themesUrlForWeb.ToLower() == themesUrlForParentWeb.ToLower())
                    {
                        Logger.WriteWarning("The web {0} inherits it's theme from it's parent. The theme will not be reset.", web.Url);
                        return;
                    }
                }

                // Open the existing theme
                ThmxTheme webThmxTheme = ThmxTheme.Open(web.Site, themesUrlForWeb);

                // Generate a new theme using the settings defined for the existing theme
                // (this will generate a temporary theme folder that we'll need to delete)
                webThmxTheme.GenerateThemedStyles(true, web.Site.RootWeb, tempFolderName);

                // Apply the newly generated theme to the web
                ThmxTheme.SetThemeUrlForWeb(web, SPUrlUtility.CombineUrl(themedFolderName, tempFolderName) + "/theme.thmx", true);

                // Delete the temp folder created earlier
                web.Site.RootWeb.GetFolder(SPUrlUtility.CombineUrl(themedFolderName, tempFolderName)).Delete();

                // Reset the theme URL just in case it has changed (sometimes it will)
                using (SPSite site = new SPSite(web.Site.ID))
                    using (SPWeb web2 = site.OpenWeb(web.ID))
                    {
                        string updatedThemesUrlForWeb = ThmxTheme.GetThemeUrlForWeb(web2);
                        if (resetChildren)
                        {
                            bool isPublishingWeb = false;
#if MOSS
                            isPublishingWeb = PublishingWeb.IsPublishingWeb(web2);
#endif
                            // Set all child webs to inherit.
                            if (isPublishingWeb)
                            {
#if MOSS
                                PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web2);
                                pubWeb.ThemedCssFolderUrl.SetValue(pubWeb.Web.ThemedCssFolderUrl, true);
#endif
                            }
                            else
                            {
                                ResetChildWebs(web2, updatedThemesUrlForWeb);
                            }
                        }
                        else
                        {
                            if (themesUrlForWeb != updatedThemesUrlForWeb)
                            {
                                UpdateInheritingWebs(web2, themesUrlForWeb, updatedThemesUrlForWeb);
                            }
                        }
                    }
            }
            finally
            {
                if (web != null)
                {
                    web.Site.Dispose();
                }
            }
        }