Posted on:
Categories: SharePoint;CodePlex
Description:

​I'm currently working on a project for a client that requires some extra pages in the My Sites portal.  These pages are an extension of user's profile, and need to be visible to all users when viewing all the user profiles.  So, to make these available to all users you would just go into the site's Quick Launch settings and then just add some new headings or links.    

Everything looks good when you are viewing your own user profile, the links appear in the left navigation as you'd expect under "About" and "Newsfeed".  When you go to look at someone else's profile though, all your newly added links disappear.  This is with both the out of the box master page, and with a custom one.  

After testing a few other things to try and isolate or work around the issue (e.g. Adding links as the farm account or the application pool account) nothing seemed to work, so I had to create a support ticket with Microsoft.  It didn't take longer than an hour to be able to have Microsoft reproduce this issue, and after some back and forth I was informed that this is being acknowledged as a bug and that there currently is no workaround for it and because it is newly discovered there isn't an ETA on a hotfix.  

Because of my client's need for having these extra pages available in the navigation for all their users I had to come up with a workaround.  To do this, I decided that JavaScript could be leveraged to add the required navigation links.  

For this I created a new SharePoint 2013 Farm Solution (the included JavaScript could be used in a SandBoxed solution as well, but I wanted to use a UserControl so I could generate the menu options and HTML in C# and just use the JavaScript to add the HTML to the navigation).    

The SharePoint solution looks like the following (you can download the solution from CodePlex - link at the bottom): 

Visual Studio Solution

So for a brief overview of the elements: 

  • SLMySitesNavInjectionUserControl - Contains all the logic that generates the required HTML for the new menu items and adds all the required JavaScript and JavaScript include files to the current page
  • jquery-1.10.1.min.js - jQuery library include (you could switch to the newer 2.0 library if you wanted, but I required IE8 support still)
  • SLMySitesNavInjection.js - JavaScript that actually adds the HTML items generated by the User Control to the Left Navigation on the page
  • MySitesNavInjectionControlRegistration - an empty SharePoint element that contains the control registration to add the SLMySitesNavInjectionUserControl to the site
  • Definitions.cs - internal static class containing constants (e.g. include files, HTML templates...) used in the solution
  • UlsHelper.cs - a static class containing some useful methods for writing to the SharePoint ULS log
So for ease of implementation, and to keep it all simple, all the links that are to be added to the site are managed in a 2-dimensional array in the Definitions.cs file: 
internal static readonly string[,] ProfilePageLinks = new[,]
 {
  {"/mypage1.aspx", "Page 1"},
  {"/mypage2.aspx", "Page 2"},
  {"/mypage3.aspx", "Page 3"}
 };

To add or remove links you just need to manage the items in this array (I know there are a number of better options to make this more manageable with out requiring a WSP update on the farm, but I'm really hoping this is temporary and that Microsoft will have this all fixed in a future CU).

After you've updated this array with all your links all you need to do to get this solution working on your My Site Portal is:

  • Package the solution as a WSP
  • Deploy the WSP to your SharePoint 2013 Farm
  • Navigate to your My Site Portal and activate the included Site Feature: "SL My Sites Nav Injection Feature"

Now you should see your specified links all the time in the left navigation.

Note - there are some limitations though.  The way this is built the links won't be added to user's personal sites (e.g. SkyDrive Pro, blog, ...) just to the user profiles site.

To download this solution from CodePlex go here: http://sp2013mysitesnavinjection.codeplex.com/