Globally changing the site theme in CS 2007

Most of the readers of this blog know about Community Server.  Which makes this a little easier, if you don't, then read up on it here Community Server.

In CS 2007, telligent have given you the option to change, and configure the theme you are using.  Personally I think this was in recognition of aero, but who knows.  Changing this theme, ONLY changes the theme for the anonymous user, so you have to either go through each user to change the theme, which can take alot of time, if your site (like mine) has 1000's of users.

So I've come up with this code, from back before NB Development became Community Server based.  It's a bit of code that sits in the master page, and updates the user's profile to the new theme.

Now it's not perfect, but it goes some way to doing what should be done.

Here's the steps:

Go to your old theme's master page.  Usually Default (Lean and Green).  ~/themes/default/common/Master.master.  Or home.aspx, if you only want this on the 1st page.

Add this code to the OnInit procedure: 

if (CSContext.Current.User.Theme.Equals("%old theme%")) {
    CSContext.Current.User.Theme = "%new theme%";
    CSContext.Current.User.Profile.Save();
    CommunityServer.Users.UpdateUser(CSContext.Current.User);
    Response.Redirect("~/");
}

Replace %old theme% with the old theme's directory name
Replace
%new theme% with the new theme's directory name

      The last line, Response.Redirect("~/"); is important because of the URL mapping that occurs in CS 2007.  The default home page is actually mapped to ~/themes/default/common/home.aspx, so you need to redirect to ~/ to refresh the mapping to ~/themes/%new theme%/common/home.aspx.

      Hope that helps.  More CS 2007 tips soon from me

      /* end of log */


      Posted Feb 25 2007, 04:08 PM by Nick

      Comments

      Dev Log wrote CS 2007 - Adding a Blog Post List to the home page
      on 02-25-2007 9:31 AM

      It's my 3rd blog post about Community Server 2007 in 2 hours, and this one is a really nice one,