Programmatically Add Links to SharePoint My Links

The first step is to get a reference to the UserProfileManager.


using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

You’ll need to pass in a reference to the current SSP by using ServerContext.Current.

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

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

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 their My Sites page.


UserProfileManager userProfileManager = new UserProfileManager(ServerContext.Current);
UserProfile currentUser = userProfileManager.GetUserProfile(true);
QuickLinkManager quickLinkManager = currentUser.QuickLinks;
quickLinkManager.Create("My Quick Link", "http://www.dotnetmafia.com", QuickLinkGroupType.General, null, Privacy.Private);
Getting a list of My Links
foreach (QuickLink quickLink in quickLinkManager.GetItems())
{
Console.WriteLine(quickLink.Url);
}

Source: Corey Roth