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.
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())
Follow me on twitter.