Friday 13 April 2012

Read / Write User Profiles in Sharepoint

C#
//Include a reference to the Microsoft.Office.Server assembly, and add the following using statement to your class
//using Microsoft.Office.Server.UserProfiles;

//Get the current user
SPWeb litwareWeb = SPControl.GetContextWeb(Context);
SPUser currentUser = litwareWeb.CurrentUser;
//Create a Link Button
LinkButton mySiteButton = new LinkButton();
//Create a new UserProfileManager
UserProfileManager pManager = new UserProfileManager();
//Get the User Profile for the current user
UserProfile uProfile = pManager.GetUserProfile(currentUser.LoginName);
mySiteButton.Text = "Go to My Site";
//Retrieve User Profile Information
mySiteButton.PostBackUrl = uProfile.PersonalSite.Url;

VB
//Include a reference to the Microsoft.Office.Server assembly, and add the following Imports statement to your class
//Imports Microsoft.Office.Server.UserProfiles

'Get the current user
Dim litwareWeb As SPWeb = SPControl.GetContextWeb(Context)
Dim currentUser As SPUser = litwareWeb.CurrentUser
'Create a Link Button
Dim mySiteButton as LinkButton = new LinkButton()
'Create a new UserProfileManager
Dim pManager As UserProfileManager = new UserProfileManager()
'Get the User Profile for the current user
Dim uProfile As UserProfile = pManager.GetUserProfile(currentUser.LoginName)
mySiteButton.Text = "Go to My Site"
'Retrieve User Profile Information
mySiteButton.PostBackUrl = uProfile.PersonalSite.Url

The User Profile store also maintains a change log that records the changes to the user profiles in the database. The GetRecentChanges method in the User Profile object model enables you to access the change log programmatically.

No comments:

Post a Comment