Skip to main content

SharePoint

Go Search
Home
SharePoint
  
Mark Wagner - Cogitation Blog > SharePoint > SharePoint Wiki Pages > SPUser and UserProfile  

SPUser and UserProfile

SharePoint User Information: SPUser and UserProfile
 
 
UserProfile (must have MOSS 2007)

UserProfileManager userMgr = new UserProfileManager(ServerContext.GetContext(SPContext.Current.Site));

UserProfile profile = userMgr.GetUserProfile(userLogin);

 

SPUser (MOSS or WSS)

Get a User (SPUser) from the root Web site in the root Site collection of the current web application.

SPUser user = SPContext.Current.Site.WebApplication.Sites["/"].RootWeb.Users[loginName];

 

The EnsureUser method will return the SPUser object for the specified user login.  The user will be added to the site if the user does not already exist.  This will ensure an SPUser object is always returned.

SPContext.Current.Web.EnsureUser(@"domain\user");

Last modified at 9/3/2008 12:39 PM  by Mark