Re-add the My Links Functionality as in SharePoint 2007 to Your 2010 Site

If you want your My Links functionality back on SharePoint 2010, than this article is something for you.
Page Content
Clients that migrate from SharePoint 2007 to SharePoint 2010 may miss the old My Links functionality in their “new” environment.
In SharePoint 2007, you had the option to add sites to your My Site by clicking on a link in the User Context Menu.
My Links Functionality in SharePoint 2007
In SharePoint 2010 this option is not there anymore.
SharePoint 2010 - User Context Menu
The functionality is still there, but only for adding libraries to My Links. It can be found on the Library tab -> Connect to Office -> Add to SharePoint Sites.
SharePoint 2010 Document Library - Add to Sharepoint Sites
Laura Rogers made a blog post to make the My Links available on the My Site. Her post can be found on the following URL: SharePoint 2010 – Where’d “My Links” Go?.
But what if you want to add SharePoint sites or lists to the My Links section?
This requires some manual steps to add the links to the My Links section. Most clients would not like this, they just want it to work as it did in SharePoint 2007.
In this post I will explain my approach to “re-add” the same functionality as in SharePoint 2007. The result would look like this.
SharePoint 2010 - User Context Menu With My Links Functionality

Add to My Links Custom Action

The first thing I will explain is how to add the Add to My Links option to the User Context Menu.
In SharePoint 2007, three pages were being used when you clicked on the Add to My Links. The first page that opened was the /_Layouts/QuickLinksDialog.aspx page. This page contained an iframe that opened the /_Layouts/QuickLinksDialog2.aspx that immediately did a form submission to the /_Layouts/QuickLinksDialogForm.aspx page.
These pages still exist in SharePoint 2010, but they give you some JavaScript errors. For this reason I created a new application page that automatically does a form submission with Query String variables.
This is the markup for the application page.

01 <html>
02         <head>
03                 <title>Add Site to My Links</title>
04         </head>
05         <body>
06                 <form id="ctl00" target="_self" action="QuickLinksDialog2.aspx" method="post" name="ctl00">
07                         <input id="QuickLinksTitle" type="hidden" value="" name="QuickLinksTitle">
08                         <input id="QuickLinksUrl" type="hidden" value="" name="QuickLinksUrl">
09  
10                         <script language="Javascript">
11                                 var form = document.forms[0];
12  
13                                 form.QuickLinksTitle.value = queryString(‘Title’).replace(/ /g, " ");
14                                 form.QuickLinksUrl.value = queryString(‘URL’);
15  
16                                 form.action = ‘/_layouts/QuickLinksDialogForm.aspx’;
17                                 form.submit();
18  
19                                 //Retrieve the query string variable
20                                 function queryString(name) {
21                                         name = name.replace(/[\[]/, "\\\[").replace(/[]]/, "\\\]");
22                                         var regexS = "[\\?&]" + name + "=([^&#]*)";
23                                         var regex = new RegExp(regexS);
24                                         var results = regex.exec(window.location.href);
25  
26                                         if (results == null)
27                                                 return "";
28                                         else
29                                                 return results[1];
30                                 }
31                         </script>
32                        
33                 </form>
34         </body>
35 </html>

The next step is to create a custom action that adds a link to the User Context Menu. To make it SharePoint 2010 “friendly”, the application page will be opened in a common dialog window. For this I created a small JavaScript function that can easily be called from the custom action.

01 function Mylinks_Dialog(siteURL, Title, URL) {
02     var options = {
03         title: "Add to My Links",
04         showClose: true,
05         allowMaximize: false,
06         autoSize: true,
07         url: siteURL + ‘/_layouts/estruyf.mylinks/estruyf.QuickLinksDialog.aspx?Title=’ + Title + ‘&URL=’ + URL
08     };
09     SP.UI.ModalDialog.showModalDialog(options);
10 }

This JavaScript function is also added by a custom action. The custom action markup looks like this.

1 <CustomAction
2         ScriptSrc="/_layouts/estruyf.mylinks/estruyf.mylinks.js"
3         Location="ScriptLink"
4         Sequence="100">
5 </CustomAction>

The last step is to add the custom action which adds the Add to My Links option to the User Context Menu. The custom action markup looks like this.

01 <CustomAction
02                 Id="estruyfAddLink"
03                 GroupId="PersonalActions"
04                 Location="Microsoft.SharePoint.StandardMenu"
05                 Sequence="1"
06                 Title="Add to My Links"
07                 Description="Add this page or any other to your Links list."
08                 ImageUrl="/_layouts/images/ctoa32.png">
09         <UrlAction Url="javascript:Mylinks_Dialog(‘{SiteUrl}’, document.title, window.location.href);" />
10 </CustomAction>

As you can see in the UrlAction in the Mylinks_Dialog function is called. This would give the following result in SharePoint.
Add to My Links Dialog

Manage Links Custom Action

Now that I’ve explained how to add the Add to My Links, the next step is to add the Manage Links option to your site. This is an easy step, because you only need to create a custom action that links to the /_Layouts/MyQuickLinks.aspx page. This is the same page that is used in SharePoint 2007.

01 <CustomAction
02                 Id="estruyfMyLinks"
03                 GroupId="PersonalActions"
04                 Location="Microsoft.SharePoint.StandardMenu"
05                 Sequence="2"
06                 Title="Manage Links"
07                 Description="Reorganize or delete items in your Links list."
08                 ImageUrl="/_layouts/images/ctom32.png">
09         <UrlAction Url="~site/_layouts/MyQuickLinks.aspx" />
10 </CustomAction>

Manage My Links Page

Files

If you want to install this solution you can download the my SharePoint 2010 solution file.
Deploy the solution to your SharePoint environment and activate the following site collection feature: estruyf MyLinks Feature.
estruyf MyLinks Feature
If you want to make changes to the code, here is my Visual Studio project.

VS Project

Result

 

 

Advertisements