Programmatically adding My Site Quick Links in SharePoint 2010

I recently had this question on how to programmatically add My Site Quick Links in SharePoint 2010.

This can be achieved using QuickLinkManager Class to create quick links.

http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.quicklinkmanager.aspx

public void AddQuickLinks()
        {
            SPSite site = new SPSite(“SITEURL”);
            SPServiceContext serviceContext =SPServiceContext.GetContext(site);
            UserProfileManager upm = newUserProfileManager(serviceContext);
            // This is just an example and hence username is hardcoded but basically you can loop through Users and pass their Username.
            string strUser = “DOMAIN\\USERNAME”;
            if (upm.UserExists(strUser))
            {
                UserProfile u = upm.GetUserProfile(strUser);
                QuickLinkManager qlm = u.QuickLinks;
                // I have hard coded the link but you will be reading these from your SQL DB.
                string strTitle = “mylink”;
                string sLinkUrl = “http://my”;
                string strGroup = “my group”;
                QuickLink ql = qlm.Create(strTitle, sLinkUrl, QuickLinkGroupType.UserSpecified, strGroup,Privacy.Public);
                ql.Commit();
            }
        }