Adding a Link to My Links Programmatically

Posted Wednesday, April 22, 2009 9:49 AM by CoreyRoth

Today, I am going to talk about how to work with the My Links functionality in MOSS using the API.  The first thing to know is that the API calls it a QuickLink.  Knowing this makes it that much easier on finding information you need in the SDK to work with them.  I figured this list worked like a regular SharePoint list, but in fact it is quite a bit different (which is why I am posting today).  QuickLinks are tied to the user’s profile in MOSS, so you will need to make a reference to Microsoft.Office.Server.dll, if you haven’t already.  You’ll then want the following references in your class.

using Microsoft.Office.Server;

using Microsoft.Office.Server.UserProfiles;

The first step is to get a reference to the UserProfileManager.  You’ll need to pass in a reference to the current SSP by using ServerContext.Current.

UserProfileManager userProfileManager = new UserProfileManager(ServerContext.Current);

After that you get the current user’s profile.  Passing true, will create the user’s profile if it doesn’t exist.

UserProfile currentUser = userProfileManager.GetUserProfile(true);

The QuickLinkManager class provides what we need to add, remove, or iterate through the links the user currently has.

QuickLinkManager quickLinkManager = currentUser.QuickLinks;

quickLinkManager.Create("My Quick Link", "", QuickLinkGroupType.General, null, Privacy.Private);

Once we have a reference to the manager, a call to the Create method is all we need.  It takes a few parameters.  The first parameter is the title followed by the URL.  The third and fourth parameters, can be used to specify a built-in group (using the QuickLinkGroupType.General enum) or by specifying a string in the next parameter to create a new one.  Finally, the last parameter, specifies the privacy settings of the link.  For the purpose of the My Links menu, you would usually choose Privacy.Private.  However, you can specify other settings as well for sharing the users links on his or her My Sites page.

You can also iterate through the user’s QuickLinks pretty easily using the GetItems() method.  For example:

foreach (QuickLink quickLink in quickLinkManager.GetItems())




Follow me on twitter.

Filed under: ,


# Adding a Link to My Links Programmatically

Sunday, April 26, 2009 10:38 PM by Confluence: SharePoint Development Wiki

Source: Corey Roth

# Programmatically Adding Links to SharePoint My Links « Christian Fleischhacker

Pingback from  Programmatically Adding Links to SharePoint My Links « Christian Fleischhacker

# re: Adding a Link to My Links Programmatically

Friday, June 15, 2012 4:03 AM by Ashwin

Link title will not take more than 50chars. Is there any reason?

# re: Adding a Link to My Links Programmatically

Tuesday, August 7, 2012 1:24 PM by CoreyRoth

@Ashwin It's just a limitation I am afraid.

# re: Adding a Link to My Links Programmatically

Friday, August 24, 2012 2:40 PM by Jim Dubreville

Any ideas on how to do this on a GET request?  Whenever I try to add a Quick Link I get told the SPWeb AllowsUnsafeUpdate flag is incorrect.  If I set that flag on the current SPWeb or the user's MySite SPWeb i still get the error.

# Adding a Link to My Links Programmatically |

Pingback from  Adding a Link to My Links Programmatically |

Leave a Comment