Welcome to Comunidade Bloggers |create|it| Sign in | Join | Help

André Vala

SharePoint
Office
FAST Search Server
.Net

News

  • European SharePoint Community Awards 2012 Winner
    Locations of visitors to this page

    Comunidade Portuguesa de SharePoint

    View André Vala's profile on LinkedIn

    © André Vala and Create IT, 2006-2011. Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to André Vala and Create IT with appropriate and specific direction to the original content.

SharePoint Tip #20: Get User Profile

User Profiles are a central concept to Office SharePoint Server 2007. They store all the information about the SharePoint users in a central location, the User Profile Store, allowing that information to be indexed and searched. The User Profile store can be populated and synchronized with several data sources:

  • Active Directory directory services
  • LADP Directory (other than Active Directory)
  • Databases and web services, via Business Data Catalog
  • Custom sources, via the User Profiles object model

You can also add users to it manually. Additionally, you can add custom properties to the User Profile and map some of them to the data sources you have. This great flexibility allows a multitude of scenarios. In this post I'll show you how you can get access a User Profile programmatically.

Everything is starts with the UserProfileManager object. Here is how you use it to get a UserProfile object.

// open a site collection
using (SPSite site = new SPSite("http://myportal"))
{
    // get the server context
    ServerContext context = ServerContext.GetContext(site);

    // create the profile manager object
    UserProfileManager profileManager = new UserProfileManager(context);

    // get the user profile
    UserProfile profile = profileManager.GetUserProfile("domain\\username");
}

There constructor for the UserProfileManager class is overloaded, which means there are other ways to create an instance but this is the way I usually do it. The GetUserProfile method is also overloaded, allowing you to get a user profile using its ID or just getting the current user's profile.

Attention: User Profiles are a MOSS only feature. You cannot use them with WSS.

Posted: Tuesday, October 14, 2008 5:58 PM by andrevala

Comments

André Vala said:

The User Profile is the central concept behind the personalization features of SharePoint. In addition

# October 18, 2008 12:25 PM

agus supriatna said:

Hi, I was try ur code but I got this message session: System.NullReferenceException: Object reference not set to an instance of an object. at SmartPart.uprofile.b__0() at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state) at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at SmartPart.uprofile.Page_Load(Object sender, EventArgs e) will u to helpme thanks in advance
# April 13, 2010 12:05 AM
Anonymous comments are disabled