Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I was wondering how I change the MySite theme from the default blue/white look to the Oslo look, or one of the other default themes?

share|improve this question

2 Answers 2

As Moontear says you need a feature stapler for My Site.

In my last project I had a project in Visual Studio only for stapling with a Feature and an Empty Module

This is the Elements.xml of the StaplingModule

<!-- Custom Master This is for Branding MySite-->
<FeatureSiteTemplateAssociation Id="63816940-bea4-4686-86f6-79f40eaab434" TemplateName="SPSPERS#2" />

<!-- Lists Instances -->
<FeatureSiteTemplateAssociation Id="4008c0da-0127-4386-94e2-9ee8740d2420" TemplateName="SPSPERS#2" />

<!-- SharePoint Server Publishing Infrastructure (Necessary so that Create Custom List appears in _layouts/addanapp.aspx. I needed to create Custom lists in mysite) -->
<FeatureSiteTemplateAssociation Id="f6924d36-2fa8-4f0b-b16d-06b7250180fa" TemplateName="SPSPERS#2" />

Now in the feature (I called it FeatureStaplingMySite) you need to make reference to the Elements.xml of the Module

<Feature Id="FEATURE-GUID" Scope="WebApplication" Description="$Resources:Intranet, Feature_MySite_Stapling_Description;" AlwaysForceInstall="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
      <ElementManifest Location="StaplingMySite\Elements.xml" />
  </ElementManifests>
</Feature>

Besides, I have another VS Project to customize mySite with a feature that activates my custom master. You can add an event receiver on that feature to activate the oslo.master for example with this code

public class FeatureMySiteMasterEventReceiver : SPFeatureReceiver
{

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        if (properties != null)
        {
            SPSite sitio = properties.Feature.Parent as SPSite;
            SPWeb web = sitio.RootWeb;
            try
            {
                ActivateMaster(web, "oslo.master", false);
                ActivateMaster(web, "oslo.master", true);
            }
            catch (Exception ex)
            {
                //Error treatment
            }                
        }
    }

    public static void ActivateMaster(SPWeb webContext, string masterPath, bool masterAdmin)
    {
        try
        {
            webContext.AllowUnsafeUpdates = true;
            if (!rutaMaster.Contains("/_catalogs/masterpage/"))
            {
                rutaMaster = SPUtility.ConcatUrls("/_catalogs/masterpage/", rutaMaster);
            }
            Uri uriMaster = new Uri(SPUtility.ConcatUrls(webContext.Url, rutaMaster));
            if (masterAdmin)
            {
                if (!webContext.MasterUrl.Contains(masterPath))
                {
                    webContext.AllProperties["OldMasterUrl"] = webContext.MasterUrl;
                }
                try
                {
                    webContext.MasterUrl = uriMaster.AbsolutePath;
                    webContext.Update();
                }
                catch (Exception ex)
                {
                    //Error treatment
                }
            }
            else
            {
                if (!webContext.CustomMasterUrl.Contains(masterPath))
                {
                    webContext.AllProperties["OldMasterUrl"] = webContext.CustomMasterUrl;
                }
                try
                {
                    webContext.CustomMasterUrl = uriMaster.AbsolutePath;
                    webContext.Update();
                }
                catch (Exception ex)
                {
                    //Error treatment
                }
            }
        }
        catch (Exception ex)
        {
            //Error Treatment
        }
        finally
        {
            webContext.AllowUnsafeUpdates = false;
        }
    }
}
share|improve this answer

You should either have a feature stapler for your my sites, like explained here:

If you want to change the theme for existing MySites you could do it by code like so:

ThmxTheme oTheme = ThmxTheme.Open(siteCollection,"_catalogs/theme/<nameoftheme>.thmx");
oTheme.ApplyTo(oWeb, false);
oWeb.Update();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.