# Friday, January 29, 2010

Required using statements

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

Then sample code

try
{
   site = SPContext.Current.Site;
   ServerContext serverContext = ServerContext.GetContext(site);
   UserProfileManager userProfileManager = new UserProfileManager(serverContext);
   UserProfile currentUserUserProfile = userProfileManager.GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);

   string nameSurname = (string)currentUserUserProfile["preferredname"].Value;
   string email = (string)currentUserUserProfile["workemail"].Value;
   string companyName = (string)currentUserUserProfile["company"].Value;
}
finally
{
   site.RootWeb.Dispose();
   site.Dispose();
}
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview