Skip to main content

Cloud

It’s MySite and I will change it if I want to!

Have you ever try changing the look and feel of your my site beyond the master page? It is not the easiest of tasks. I did some my site work for a client and the requirements were as follows:

  • Create a web part to edit custom properties.
  • Provision said web part on four pages and create pages during the my site creation.
  • Show the four pages as tabbed items at the top of the my site page and the profile page.

I am not going to discuss the web part because this post is more for changing the my site look and feel. I used feature stapling as out lined here to add features to the SPSPERS site template. I created and stapled features to do the following:

  • New MySite MasterPage.
  • Add Custom MySite web parts to the Web Part Gallery.
  • Feature Receiver to handle custom tasks that cannot be done through regular features.
  • Feature to add custom pages to the newly created MySite.
  • Feature to hide the site theme link in site settings.

The feature stapling was the easy part of the customizing…there are examples all over the web for this along with examples of changing your master page for a MySite. I used a feature receiver to accomplish some of the items that I needed to do. Listed below are the items:

  • Add navigation tabs to the new MySite
  • Change the MasterUrl property for the new MySite
  • Change the AlternateCssUrl property for the new MySite
  • Change the AlternateCssUrl for the MySite Host
  • Add navigation Tabs to the MySiteHost.

Below is an example of some code to accomplish the above tasks:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb web = null;

try
{
web = properties.Feature.Parent as SPWeb;

if (web.WebTemplate == "SPSPERS")
{
if (!TabExists(web, "Qualifications.aspx"))
web.Navigation.TopNavigationBar.AddAsLast(new SPNavigationNode("Qualifications", "ProfileQualifications.aspx", true));
if (!TabExists(web, "Training.aspx"))
web.Navigation.TopNavigationBar.AddAsLast(new SPNavigationNode("Training", "ProfileTraining.aspx", true));
if (!TabExists(web, "Languages.aspx"))
web.Navigation.TopNavigationBar.AddAsLast(new SPNavigationNode("Languages", "ProfileLanguages.aspx", true));
if (!TabExists(web, "Experience.aspx"))
web.Navigation.TopNavigationBar.AddAsLast(new SPNavigationNode("Experience", "ProfileExperience.aspx", true));

web.MasterUrl = web.MasterUrl.Replace("default.master", "mysite.master");
web.AlternateCssUrl = "/_layouts/styles/IntranetStyles/mysite.css";
web.Update();
}

SetupMySiteHost(web);
}

catch (Exception ex)
{
Handle exception
}
});
}

private void SetupMySiteHost(SPWeb web)
{
SPWeb rootWeb = GetMySiteHost(web);

if (rootWeb == null)
return;

try
{
rootWeb.AlternateCssUrl = "/_layouts/styles/IntranetStyles/intranet.css";
AddNavigationTabs(rootWeb, true);
rootWeb.Update();
}

catch (Exception ex)
{

Handle exception
}
}

Timing issues with the provisioning prevented me from doing the following tasks in the feature receiver:

  • Create two folders in the Shared Documents list
  • Create a new task list to replace the "Getting Started with MySite" web part.
  • Remove the above mentioned web part.
  • Add a content query web part to display non completed tasks from the list mentioned above.

To solve this issue I started with the MySite.aspx page that lives in the layouts folder of the 12 hive. After disassembling this page I found that this is the page responsible for the creation of the my site, so I decided to extend the functionality of this page. I started by overriding the Page_Load of the MySite.aspx page. The code looked like the following:

public class NewCreatePersonalSpace : CreatePersonalSpace
{
new protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);

if (this.IsPostBack)
{
UserProfile p = ProfileLoader.GetProfileLoader().GetUserProfile();

if (p.PersonalSite == null)
return;

SPWeb web = p.PersonalSite.OpenWeb();

//implement code here to do tasks

web.Close();
web.Dispose();
}
}

}

I started the code above by checking for postback. I did this because the base page load will redirect if the MySite and there is no need to do anything the first time this page is called. The next thing I do is get the user’s profile so that I can check to see if the SPSite object that the PersonalSite property refers to exists. If the PersonalSite property is not null then the MySite has been created. In an effort not to bore anyone reading this I will provide the code for the tasks above upon request.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.