in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.

Adding a Link to My Links Programmatically

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", "http://www.dotnetmafia.com", 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())

{

    Console.WriteLine(quickLink.Url);

}

Follow me on twitter.

Published Apr 22 2009, 09:49 AM by CoreyRoth
Filed under: ,

Comments

 

Confluence: SharePoint Development Wiki said:

Source: Corey Roth

April 26, 2009 10:38 PM
 

Programmatically Adding Links to SharePoint My Links « Christian Fleischhacker said:

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

January 12, 2012 10:41 AM
 

Ashwin said:

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

June 15, 2012 4:03 AM
 

CoreyRoth said:

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

August 7, 2012 1:24 PM
 

Jim Dubreville said:

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.

August 24, 2012 2:40 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems