Friday, February 15, 2013

Get UserProfile using SharePoint 2013 object model

In this post we will discuss about how to retrieve UserProfile properties in SharePoint 2013 using object model.

Below is the code:

using Microsoft.Office.Server.Social;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Portal.UserProfiles;

SPWeb web = SPContext.Current.Web;

SPUser currentUser = SPContext.Current.Web.CurrentUser;

SPServiceContext serverContext = SPServiceContext.GetContext(web.Site);

UserProfileManager profileManager = new UserProfileManager(serverContext);

UserProfile profile = profileManager.GetUserProfile(currentUser.LoginName);

if (profile != null)
string displayName = profile.DisplayName;

You can also check out various posts on SharePoint 2013 Developer Site Template, What's new for mobile devices in SharePoint 2013 and  some SharePoint 2013 PowerShell commands.

Twitter Delicious Facebook Digg Favorites More