none
Modifying Master Pages on Personal Sites ( My Content)

    Question

  • Hi Everyone,

    I have branded MySite and Personal site collections using the branding code but I am running into an issue.

    We are trying to give a uniform look to all the users when their personal site collections are newly created.

    Once the master page are under the personal site collections , how do I change the master pages programmatically ?

    I have written code which switches the master page to default master page ,deletes the current custom master page and activates the feature which deploys my custom branding .

    I am running into "Access Denied" error in my code when I try to execute the above code for personal  ( My Content)  sites of users.

    Any solution or hint will be much appreciated.

    Thanks,

    Shilpa

    Thursday, July 11, 2013 2:42 PM

Answers

  • To do it for existing site collections your best choice is to write some powershell that will walk through all the MySites and make the change.  The url for where the master page is stored is in a property of the SPWeb object that is the MySite.

    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Thursday, July 11, 2013 7:39 PM
  • I know in SharePoint 2010 the easiest way to accomplish this was to put that code in a server control that was added to the default.master.  When a user opens the page the first time it automatically switched the branding and removed the control.  I haven't tried it, but you should be able to accomplish something similar with the Client Side Object model and then add that .js to the default home page of the mysite site definition.

    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Thursday, July 11, 2013 3:16 PM

All replies

  • I know in SharePoint 2010 the easiest way to accomplish this was to put that code in a server control that was added to the default.master.  When a user opens the page the first time it automatically switched the branding and removed the control.  I haven't tried it, but you should be able to accomplish something similar with the Client Side Object model and then add that .js to the default home page of the mysite site definition.

    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Thursday, July 11, 2013 3:16 PM
  • Thanks for the suggestion but what if I want to change the custom master page for ex. a.master and replace it with another master page b.master for all the personal site collections that have been created.
    Thursday, July 11, 2013 3:20 PM
  • To do it for existing site collections your best choice is to write some powershell that will walk through all the MySites and make the change.  The url for where the master page is stored is in a property of the SPWeb object that is the MySite.

    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Thursday, July 11, 2013 7:39 PM
  • Thanks Paul and sorry for the late reply.

    I was trying very hard to do it in the c# code as we wanted it to be a utility but it is still failing.

    I impersonated as the user who has created the site and then tried to update the master pages ,it works for only site level but fails for websites below the root for e.g , Blog site.

    The powershell seems to be our only option currently.

    Wednesday, July 24, 2013 8:13 PM
  • If you can do it in PowerShell you should be able to do it in C#.  They use the same APIs.

    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Thursday, July 25, 2013 12:19 PM
  • The solution that I'm currently applying is the following:

    $web = get-spsite http://yoururl/mysite/user
    $web=$web.rootweb
    $web.MasterUrl = "/mysite/_catalogs_masterpage/mysite.master"
    $web.CustomMasterUrl = "/mysite/_catalogs_masterpage/mysite.master"
    $web.Update()
    
    But, I'm trying to know if it's possible to appply the new mysite master no the new users that are creating their personal site
    Wednesday, January 15, 2014 11:47 AM
  • That will work for existing mysites.  Here's an article that discusses some of the ways to do this in SharePoint 2013 for new MySites.

    http://blogs.msdn.com/b/vesku/archive/2013/08/29/customizing-sharepoint-2013-personal-sites-using-sp-apps-with-remote-provisioning.aspx 


    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

    Wednesday, January 15, 2014 4:13 PM
  • Thanks for the link.

    We solved the problem for new users by using Feature stapling .

    For exisitng users we go through all  the users and change it programmatically .The utility which does the changes runs unders the system account so that there are no authentication issues.

    Wednesday, January 15, 2014 4:33 PM